com.atlassian.confluence.core
Class DateFormatter

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

public class DateFormatter
extends Object

Formats dates and times into a given timezone. TODO: Should support user locales


Constructor Summary
DateFormatter(TimeZone timeZone, FormatSettingsManager formatSettingsManager)
          Create a date formatter for the specified timezone.
 
Method Summary
 String format(Date date)
          Formats the date and returns it as a string, using the date formatting pattern.
 String formatBlogDate(Date date)
          Formats the date as a blog posting date and returns it as a string.
 String formatDateFull(Date date)
          Formats the date and returns it as a string, using DateFormat.FULL as the formatting pattern.
 String formatDateTime(Date date)
          Formats the date and returns it as a string, using the date-time formatting pattern.
static String formatMillis(long millis)
           
 String formatServerDate(Date date)
          Same as format(Date), but doesn't perform time zone conversion.
 String formatServerDateFull(Date date)
          Same as formatDateFull(Date), but doesn't perform time zone conversion.
 String formatServerDateTime(Date date)
          Same as formatDateTime(Date), but doesn't perform time zone conversion.
 String formatTime(Date date)
          Formats the date and returns it as a string, using the time formatting pattern.
 Calendar getCalendar()
           
 String getCurrentDateTime()
           
 
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)
Create a date formatter for the specified timezone.

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

format

public String format(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 String formatDateTime(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 String formatTime(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.


formatDateFull

public String formatDateFull(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 String formatServerDate(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 String formatServerDateTime(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 String formatBlogDate(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 String formatServerDateFull(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.


getCurrentDateTime

public String getCurrentDateTime()
Returns:
the current date formatted as per formatDateTime(Date)

getCalendar

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

formatMillis

public static 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.


Confluence is developed by Atlassian.