Class DateFormatter
FormatSettingsManager which is passed to the constructor. Also allows for formatting into arbitrary formats.
This class is not thread-safe, primarily because DateFormat implementations are not synchronised. You should construct one instance of this class per thread or request.
TODO: Should support user locales
-
Constructor Summary
ConstructorsConstructorDescriptionDateFormatter(TimeZone timeZone, FormatSettingsManager formatSettingsManager, LocaleManager localeManager) DateFormatter(TimeZone timeZone, FormatSettingsManager formatSettingsManager, LocaleManager localeManager) -
Method Summary
Modifier and TypeMethodDescriptionFormats the date and returns it as a string with a formatOption defined in JDK.Formats the date and returns it as a string, using the date formatting pattern.formatBlogDate(Date date) Formats the date as a blog posting date and returns it as a string.formatDateFull(Date date) Formats the date and returns it as a string, usingDateFormat.FULLas the formatting pattern.formatDateTime(Instant instant) Same asformatDateTime(Date)but accepting Java 8InstantformatDateTime(Date date) Formats the date and returns it as a string, using the date-time formatting pattern.formatGivenString(String formatString, Date date) Formats the date and returns it as a string, using the given formatting pattern.static StringformatMillis(long millis) formatServerDate(Date date) Same asformat(Date), but doesn't perform time zone conversion.formatServerDateFull(Date date) Same asformatDateFull(Date), but doesn't perform time zone conversion.formatServerDateTime(Date date) Same asformatDateTime(Date), but doesn't perform time zone conversion.formatServerDateWithUserLocale(int formatOption, Date date) Same asformat(int, Date), but doesn't perform time zone conversion.formatTime(Date date) Formats the date and returns it as a string, using the time formatting pattern.formatTimeMedium(Date date) Formats the date and returns it as a string, usingDateFormat.MEDIUMas the time formatting pattern.getDateForBlogPost(Date date) getTimeForBlogPost(Date date)
-
Constructor Details
-
DateFormatter
public DateFormatter(TimeZone timeZone, FormatSettingsManager formatSettingsManager, LocaleManager localeManager) -
DateFormatter
public DateFormatter(TimeZone timeZone, FormatSettingsManager formatSettingsManager, LocaleManager localeManager)
-
-
Method Details
-
format
Formats the date and returns it as a string, using the date formatting pattern. This format might be 'yyyy-MM-dd' or something similar.The
TimeZonespecified in the constructor is used to convert the date from server time to the user's local time. -
formatDateTime
Formats the date and returns it as a string, using the date-time formatting pattern. This format might be 'yyyy-MM-dd HH:mm:ss' or something similar.The
TimeZonespecified in the constructor is used to convert the date from server time to the user's local time. -
formatDateTime
Same asformatDateTime(Date)but accepting Java 8Instant- Since:
- 7.14
-
formatTime
Formats the date and returns it as a string, using the time formatting pattern. This format might be 'HH:mm:ss' or something similar.The
TimeZonespecified in the constructor is used to convert the date from server time to the user's local time. -
formatTimeMedium
Formats the date and returns it as a string, usingDateFormat.MEDIUMas the time formatting pattern.The
TimeZonespecified in the constructor is used to convert the date from server time to the user's local time. -
formatDateFull
Formats the date and returns it as a string, usingDateFormat.FULLas the formatting pattern.The
TimeZonespecified in the constructor is used to convert the date from server time to the user's local time. -
format
Formats the date and returns it as a string with a formatOption defined in JDK.The
TimeZonespecified in the constructor is used to convert the date from server time to the user's local time. -
formatServerDate
Same asformat(Date), but doesn't perform time zone conversion.This is typically used for formatting the posting dates of news items, which must be represented the same for all users.
-
formatServerDateWithUserLocale
Same asformat(int, Date), but doesn't perform time zone conversion.This is typically used for formatting the posting dates of news items, which must be represented the same for all users.
-
formatServerDateTime
Same asformatDateTime(Date), but doesn't perform time zone conversion.This is typically used for formatting the posting dates of news items, which must be represented the same for all users.
-
formatBlogDate
Formats the date as a blog posting date and returns it as a string. The format might be 'dd MMM @ h:mm a' or something similar.This method does not apply the
TimeZonespecified in the constructor, but instead uses server's default time zone. A blog post date is part of its identifier, therefore it must be consistent for all users. -
formatServerDateFull
Same asformatDateFull(Date), but doesn't perform time zone conversion.This is typically used for formatting the posting dates of news items, which must be represented the same for all users.
-
formatGivenString
Formats the date and returns it as a string, using the given formatting pattern.The
TimeZonespecified in the constructor is used to convert the date from server time to the user's local time. -
getCurrentDateTime
- Returns:
- the current date and time formatted as per
formatDateTime(Date)
-
getCurrentDate
- Returns:
- the current date formatted as per
format(Date)
-
getDateForBlogPost
- Returns:
- the given date time in editor blog post format
-
getTimeForBlogPost
- Returns:
- the given time in editor blog post format
-
getCalendar
- Returns:
- a Calendar for the
TimeZonespecified in the constructor.
-
getTimeZone
- Returns:
- the
TimeZoneprovided when this formatter was created. - Since:
- 2.7
-
formatMillis
- Returns:
- a String representing the millisecond value in the format '[h:]mm:ss.S'. That is, hours will only be displayed if non-zero and any trailing zeroes in the milliseconds are truncated.
-