|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.jabb.util.text.DurationFormatter
public class DurationFormatter
An utility to format the length of time period to String, for example: 00:03:01.011 or 7d, 12:32:02:001.
一个可以用来格式化时间段信息的工具类,其输出结果比如: 00:03:01.011,或:7d, 12:32:02:001。
An example of usage:
典型用法是这样的:
long t0 = System.currentTimeMillis(); ... long t1 = System.currentTimeMillis(); ... System.out.println(DurationFormatter.formatSince(t0)); // from t0 to current time ... System.out.println(DurationFormatter.format(t1-t0)); // from t0 to t1 ... Calendar calendar = new GregorianCalendar(); calendar.set(2060, 1, 31, 8, 0); // Jan 31 2060 8AM System.out.println(DurationFormatter.formatSince(calendar.getTimeInMillis()));
| Field Summary | |
|---|---|
protected static long |
ONE_DAY_IN_MILLI
|
| Constructor Summary | |
|---|---|
DurationFormatter()
|
|
| Method Summary | |
|---|---|
static String |
format(long duration)
Format the length of time period (in milliseconds) to String. 格式化时间长度(以毫秒为单位)为字符串。 |
static String |
format(long duration,
TimeUnit unit,
boolean trimLeftZeros)
Format the length of time period (in milliseconds) to String. 格式化时间长度(以毫秒为单位)为字符串。 |
static String |
formatSince(long pastOrFutureTime)
Format the length of time period between current system time and specified time to String. 格式化指定时间同当前系统时间之间的时间差为字符串。 |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final long ONE_DAY_IN_MILLI
| Constructor Detail |
|---|
public DurationFormatter()
| Method Detail |
|---|
public static String format(long duration,
TimeUnit unit,
boolean trimLeftZeros)
duration - Length of time period in millisecondsunit - The least unit that will be in the outputtrimLeftZeros - Whether to remove leading zeros from the outputpublic static String format(long duration)
duration - Length of time period in millisecondsunit - The least unit that will be in the outputpublic static String formatSince(long pastOrFutureTime)
The time specified can be in the past or in the future, in either cases, meaningful result will be get.
指定的用作同当前系统时间作比较的时间可以是在过去,也可以是在将来,这两种情况都能产生有意义的结果。
pastOrFutureTime - A time in the past or in the future
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||