Class Dates
- java.lang.Object
-
- com.atlassian.confluence.rest.serialization.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:
- 5.5
-
-
Field Summary
Fields Modifier and Type Field Description static String
DATE_FORMAT
Deprecated.since 5.7.static String
TIME_FORMAT
Deprecated.since 5.7.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
asDateString(org.joda.time.DateTime date)
Converts the given DateTime object to a String.static String
asTimeString(org.joda.time.DateTime date)
Converts the given DateTime object to a String.static org.joda.time.DateTime
fromDateString(String date)
Converts the given date String into a DateTime object.static org.joda.time.DateTime
fromTimeString(String time)
Converts the given date and time String to a DateTime object.
-
-
-
Field Detail
-
DATE_FORMAT
@Deprecated public static final String DATE_FORMAT
Deprecated.since 5.7. This date format will follow that provided byISODateTimeFormat.date()
The format used for dates in the REST plugin.- See Also:
- Constant Field Values
-
TIME_FORMAT
@Deprecated public static final String TIME_FORMAT
Deprecated.since 5.7. This date time format will follow that provided byISODateTimeFormat.dateTime()
The format used for times in the REST plugin.- See Also:
- Constant Field Values
-
-
Method Detail
-
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 dateIllegalArgumentException
- 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
-
-