Class DateCache

java.lang.Object
org.eclipse.jetty.util.DateCache

public class DateCache extends Object
Date Format Cache. Computes String representations of Dates and caches the results so that subsequent requests within the same second will be fast. Only format strings that contain either "ss". Sub second formatting is not handled. The timezone of the date may be included as an ID with the "zzz" format string or as an offset with the "ZZZ" format string. If consecutive calls are frequently very different, then this may be a little slower than a normal DateFormat.
  • Field Details

  • Constructor Details

    • DateCache

      public DateCache()
      Constructor. Make a DateCache that will use a default format. The default format generates the same results as Date.toString().
    • DateCache

      public DateCache(String format)
      Constructor. Make a DateCache that will use the given format
      Parameters:
      format - the format to use
    • DateCache

      public DateCache(String format, Locale l)
    • DateCache

      public DateCache(String format, Locale l, String tz)
    • DateCache

      public DateCache(String format, Locale l, TimeZone tz)
  • Method Details

    • getTimeZone

      public TimeZone getTimeZone()
    • format

      public String format(Date inDate)
      Format a date according to our stored formatter.
      Parameters:
      inDate - the Date
      Returns:
      Formatted date
    • format

      public String format(long inDate)
      Format a date according to our stored formatter. If it happens to be in the same second as the last formatNow call, then the format is reused.
      Parameters:
      inDate - the date in milliseconds since unix epoch
      Returns:
      Formatted date
    • formatNow

      public String formatNow(long now)
      Format a date according to our stored formatter. The passed time is expected to be close to the current time, so it is compared to the last value passed and if it is within the same second, the format is reused. Otherwise a new cached format is created.
      Parameters:
      now - the milliseconds since unix epoch
      Returns:
      Formatted date
    • now

      public String now()
    • tick

      public DateCache.Tick tick()
    • formatTick

      protected DateCache.Tick formatTick(long now)
    • getFormatString

      public String getFormatString()