Time { public static String makeTimeStringRounded(long t, TimeUnit unit) { long nanos = unit.toNanos(t); return makeTimeStringNanoRounded(nanos); }  static String makeDateString(); static String makeDateString(long date); static String makeDateString(Date date); static String makeDateString(Date date, String format); static String makeDateString(Date date, String format, @Nullable TimeZone tz); static String makeDateString(Calendar date); static String makeDateString(Calendar date, String format); static Function<Long, String> toDateString(); static String makeDateStampString(); static String makeDateStampString(long date); static String makeDateSimpleStampString(); static String makeDateSimpleStampString(long date); static Function<Long, String> toDateStampString(); static String makeTimeStringExact(long t, TimeUnit unit); static String makeTimeStringRounded(long t, TimeUnit unit); static String makeTimeStringRounded(@Nullable Stopwatch timer); static String makeTimeStringExact(long t); static String makeTimeStringRounded(long t); static String makeTimeStringRoundedSince(long utc); static String makeTimeStringExact(@Nullable Duration d); static String makeTimeStringRounded(@Nullable Duration d); static String makeTimeString(long t, boolean round); static String makeTimeStringNanoExact(long tn); static String makeTimeStringNanoRounded(long tn); static String makeTimeStringNano(long tn, boolean round); static Function<Long, String> fromLongToTimeStringExact(); static Function<Long, String> fromLongToTimeStringRounded(); static Function<Duration, String> fromDurationToTimeStringRounded(); static void sleep(long millis); static void sleep(Duration duration); static long getTimeOfDayFromUtc(long timeUtc); static long getTimeUtc(TimeZone zone, int year, int month, int date, int hourOfDay, int minute, int second, int millis); static long roundFromMillis(long millis, TimeUnit units); static long roundFromMillis(long millis, long millisPerUnit); static long timeRemaining(long startTime, long maxTime); static Duration parseDuration(@Nullable String timeString); static long parseElapsedTime(String timeString); static double parseElapsedTimeAsDouble(final String timeStringOrig); static Calendar newCalendarFromMillisSinceEpochUtc(long timestamp); static Calendar newCalendarFromDate(Date date); static Date parseDate(@Nullable String input); static Calendar parseCalendar(@Nullable String input); static Maybe<Calendar> parseCalendarMaybe(@Nullable String input); static TimeZone getTimeZone(String code); static Maybe<String> getTimeZoneOffsetString(String tz, int year, int month, int day); @SuppressWarnings("deprecation") static String getTimeZoneOffsetString(TimeZone tz, int year, int month, int day); static Maybe<Calendar> parseCalendarFormat(String dateString, String format); static Maybe<Calendar> parseCalendarFormat(String dateString, DateFormat format); static Date dropMilliseconds(Date date); static Duration elapsedSince(long timestamp); static boolean hasElapsedSince(long timestamp, Duration duration); static long now(); static final String DATE_FORMAT_PREFERRED_W_TZ; static final String DATE_FORMAT_PREFERRED; static final String DATE_FORMAT_STAMP; static final String DATE_FORMAT_SIMPLE_STAMP; static final String DATE_FORMAT_OF_DATE_TOSTRING; static final String DATE_FORMAT_ISO8601; static final String DATE_FORMAT_ISO8601_NO_MILLIS; static final long MILLIS_IN_SECOND; static final long MILLIS_IN_MINUTE; static final long MILLIS_IN_HOUR; static final long MILLIS_IN_DAY; static final long MILLIS_IN_YEAR; static final TimeZone TIME_ZONE_UTC; }
@Test public void testMakeTimeStringFromStopwatch() { final AtomicLong time = new AtomicLong(); Ticker ticker = new Ticker() { @Override public long read() { return time.get(); } }; Assert.assertNull(Time.makeTimeStringRounded((Stopwatch)null)); Stopwatch stopwatch = Stopwatch.createStarted(ticker); time.set(TimeUnit.MILLISECONDS.toNanos(1100)); Assert.assertEquals(Time.makeTimeStringRounded(stopwatch), "1.10s"); }