com.atlassian.confluence.core
Class DateFormatter

java.lang.Object
  extended by com.atlassian.confluence.core.DateFormatter

public class DateFormatter
extends java.lang.Object

Formats dates and times into a given timezone in a variety of formats. The actual formats are provided by the FormatSettingsManager which is passed to the constructor. Also allows for formatting into aribitrary 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
DateFormatter(TimeZone timeZone, FormatSettingsManager formatSettingsManager)
          Deprecated. Since 3.2 use com.atlassian.confluence.core.DateFormatter#DateFormatter(com.atlassian.confluence.core.TimeZone, com.atlassian.confluence.core.FormatSettingsManager, com.atlassian.confluence.languages.LocaleManager) Create a date formatter for the specified timezone.
DateFormatter(TimeZone timeZone, FormatSettingsManager formatSettingsManager, LocaleManager localeManager)
           
 
Method Summary
 java.lang.String format(java.util.Date date)
          Formats the date and returns it as a string, using the date formatting pattern.
 java.lang.String formatBlogDate(java.util.Date date)
          Formats the date as a blog posting date and returns it as a string.
 java.lang.String formatDateFull(java.util.Date date)
          Formats the date and returns it as a string, using DateFormat.FULL as the formatting pattern.
 java.lang.String formatDateTime(java.util.Date date)
          Formats the date and returns it as a string, using the date-time formatting pattern.
 java.lang.String formatDay(java.util.Date date)
           
 java.lang.String formatGivenString(java.lang.String formatString, java.util.Date date)
          Formats the date and returns it as a string, using the given formatting pattern.
static java.lang.String formatMillis(long millis)
           
 java.lang.String formatServerDate(java.util.Date date)
          Same as format(Date), but doesn't perform time zone conversion.
 java.lang.String formatServerDateFull(java.util.Date date)
          Same as formatDateFull(Date), but doesn't perform time zone conversion.
 java.lang.String formatServerDateTime(java.util.Date date)
          Same as formatDateTime(Date), but doesn't perform time zone conversion.
 java.lang.String formatTime(java.util.Date date)
          Formats the date and returns it as a string, using the time formatting pattern.
 java.util.Calendar getCalendar()
           
 java.lang.String getCurrentDate()
           
 java.lang.String getCurrentDateTime()
           
 TimeZone getTimeZone()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DateFormatter

public DateFormatter(TimeZone timeZone,
                     FormatSettingsManager formatSettingsManager)
Deprecated. Since 3.2 use com.atlassian.confluence.core.DateFormatter#DateFormatter(com.atlassian.confluence.core.TimeZone, com.atlassian.confluence.core.FormatSettingsManager, com.atlassian.confluence.languages.LocaleManager) Create a date formatter for the specified timezone.

Parameters:
timeZone - the time zone in which dates will be formatted

DateFormatter

public DateFormatter(TimeZone timeZone,
                     FormatSettingsManager formatSettingsManager,
                     LocaleManager localeManager)
Method Detail

format

public java.lang.String format(java.util.Date date)
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 TimeZone specified in the constructor is used to convert the date from server time to the user's local time.


formatDateTime

public java.lang.String formatDateTime(java.util.Date date)
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 TimeZone specified in the constructor is used to convert the date from server time to the user's local time.


formatTime

public java.lang.String formatTime(java.util.Date date)
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 TimeZone specified in the constructor is used to convert the date from server time to the user's local time.


formatDay

public java.lang.String formatDay(java.util.Date date)
See Also:
FormatSettingsManager.getDayFormat()

formatDateFull

public java.lang.String formatDateFull(java.util.Date date)
Formats the date and returns it as a string, using DateFormat.FULL as the formatting pattern.

The TimeZone specified in the constructor is used to convert the date from server time to the user's local time.


formatServerDate

public java.lang.String formatServerDate(java.util.Date date)
Same as format(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

public java.lang.String formatServerDateTime(java.util.Date date)
Same as formatDateTime(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

public java.lang.String formatBlogDate(java.util.Date date)
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 TimeZone specified 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

public java.lang.String formatServerDateFull(java.util.Date date)
Same as formatDateFull(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

public java.lang.String formatGivenString(java.lang.String formatString,
                                          java.util.Date date)
Formats the date and returns it as a string, using the given formatting pattern.

The TimeZone specified in the constructor is used to convert the date from server time to the user's local time.


getCurrentDateTime

public java.lang.String getCurrentDateTime()
Returns:
the current date and time formatted as per formatDateTime(Date)

getCurrentDate

public java.lang.String getCurrentDate()
Returns:
the current date formatted as per format(Date)

getCalendar

public java.util.Calendar getCalendar()
Returns:
a Calendar for the TimeZone specified in the constructor.

getTimeZone

public TimeZone getTimeZone()
Returns:
the TimeZone provided when this formatter was created.
Since:
2.7

formatMillis

public static java.lang.String formatMillis(long millis)
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.


Copyright © 2003-2010 Atlassian. All Rights Reserved.