public class DurationFormatter extends Object
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()));
Modifier and Type | Field and Description |
---|---|
protected static long |
ONE_DAY_IN_MILLI |
Constructor and Description |
---|
DurationFormatter() |
Modifier and Type | Method and Description |
---|---|
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.
格式化指定时间同当前系统时间之间的时间差为字符串。 |
protected static final long ONE_DAY_IN_MILLI
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 millisecondspublic 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 futureCopyright © 2014. All Rights Reserved.