java.lang.Object
com.atlassian.confluence.rest.serialization.jackson2.Dates

public class Dates extends Object
Utility class for formatting and parsing date and date/time objects in ISO8601 format.

Unabashedly pinched from Jira

Since:
8.9.0
  • Field Details

    • DATE_FORMAT

      @Deprecated public static final String DATE_FORMAT
      Deprecated.
      since 5.7. This date format will follow that provided by ISODateTimeFormat.date()
      The format used for dates in the REST plugin.
      See Also:
    • TIME_FORMAT

      @Deprecated public static final String TIME_FORMAT
      Deprecated.
      since 5.7. This date time format will follow that provided by ISODateTimeFormat.dateTime()
      The format used for times in the REST plugin.
      See Also:
  • Method Details

    • asTimeString

      public static String asTimeString(org.joda.time.DateTime date)
      Converts the given DateTime object to a String. The returned string is in the format "yyyy-MM-dd\'T\'HH:mm:ss.SSSZZ".
      Parameters:
      date - a Date
      Returns:
      a String representation of the date and time
    • fromTimeString

      public static org.joda.time.DateTime fromTimeString(String time) throws IllegalArgumentException
      Converts the given date and time String to a DateTime object. The time parameter is expected to be in the format "yyyy-MM-dd\'T\'HH:mm:ss.SSSZZ".
      Parameters:
      time - a String representation of a date and time
      Returns:
      a Date
      Throws:
      RuntimeException - if there is an error parsing the date
      IllegalArgumentException - if the input string is not in the expected format
    • asDateString

      public static String asDateString(org.joda.time.DateTime date)
      Converts the given DateTime object to a String. The returned string is in the format "yyyy-MM-dd".
      Parameters:
      date - a Date
      Returns:
      a String representation of the date
    • fromDateString

      public static org.joda.time.DateTime fromDateString(String date) throws IllegalArgumentException
      Converts the given date String into a DateTime object. The date parameter is expected to be in the format "yyyy-MM-dd".
      Parameters:
      date - a String containing a date
      Returns:
      a DateTime
      Throws:
      IllegalArgumentException - if the input string is not in the expected format