Skip navigation links

Package com.atlassian.jira.datetime

A small set of classes that allow clients to format and parse dates in JIRA, in a way that is time zone and locale aware.

See: Description

Package com.atlassian.jira.datetime Description

A small set of classes that allow clients to format and parse dates in JIRA, in a way that is time zone and locale aware.

Time zones

When working with dates and times inside JIRA, it is important to understand the following time zone concepts.

By default, formatters in this package will operate using the time zone of the user that is currently logged in. If the default user time zone has not configured, it defaults to the system time zone. Similarly, if a user has not configured a user time zone, JIRA will use the default user time zone when displaying date and times to that user.

Locales

JIRA is capable of displaying dates in the default JIRA locale, and also in the user's locale, when a user has explicitly configured a different locale. By default, formatters in this package will operate using the locale of the user that is currently logged in.

Usage

Most of the work is done by implementations of the DateTimeFormatter interface. If you intent to use date, and especially date/time values in your plugin, you should have a DateTimeFormatterFactory injected into your plugin classes, which you can use to build DateTimeFormatter instances, as in the following example.

     public class MyPluginClass
     {
         private final DateTimeFormatter dateTimeFormatter;

         public MyPluginClass(DateTimeFormatter dateTimeFormatter)
         {
             // call forLoggedInUser() to associate the formatter with the currently logged in user
             this.dateTimeFormatter = dateTimeFormatter.forLoggedInUser();
         }

         // formats dates in the user's time zone and with the user's locale
         public String currentDate()
         {
             return dateTimeFormatter.withStyle(COMPLETE).format(new Date());
         }

         // formats dates in UTC and with the user's locale
         public String currentDateInUTC()
         {
             return dateTimeFormatter.withZone(TimeZone.UTC).format(new Date());
         }

         // formats dates in the user's time zone and in Dutch
         public String currentDateInDutch()
         {
             return dateTimeFormatter.withLocale(new Locale("nl")).format(new Date());
         }
     }
 
Since:
4.4
Skip navigation links

Copyright © 2002-2019 Atlassian. All Rights Reserved.