Package org.hisp.dhis.util
Class DateTimeUtils
java.lang.Object
org.hisp.dhis.util.DateTimeUtils
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic DategetDate(int year, int month, int dayOfMonth) Returns a date.static StringgetDateString(Date date) Returns a date string on the format:yyyy-MM-dd.static StringgetDateTimeString(Date dateTime) Returns a date time string on the format:yyyy-MM-dd'T'HH:mm:ss.SSS.static LocalDategetLocalDate(String string) Returns aLocalDatebased on the given string.static StringgetLocalDateString(LocalDate date) Returns a date string on the format:yyyy-MM-dd.static LocalDateTimegetLocalDateTime(String string) Returns aLocalDateTimebased on the given string using the UTC time zone.static LocalDategetLocalDateTimeAsDate(String string) Returns aLocalDatebased on the given string using the UTC time zone.static StringgetLocalDateTimeString(LocalDateTime dateTime) Returns a date time string on the format:yyyy-MM-dd'T'HH:mm:ss.SSS.static StringgetUtcDateTimeString(LocalDateTime dateTime) Returns a date time string on the format:yyyy-MM-dd'T'HH:mm:ss.SSSZ.static StringgetUtcDateTimeString(Date dateTime) Returns a date time string on the format:yyyy-MM-dd'T'HH:mm:ss.SSSZ.static booleanisValidLocalDate(String string) Indicates whether the given string can be parsed to a local date, i.e.static booleanisValidLocalDateTime(String string) Indicates whether the given string can be parsed to a local date time, i.e.static Datestatic DatetoDate(LocalDateTime dateTime) Returns aDatefrom aLocalDateTime.static InstantReturns theInstantof received date param.static LocalDatetoLocalDate(Instant instant) static LocalDatetoLocalDate(Date date) static LocalDateTimetoLocalDateTime(Instant instant) Returns theLocalDateTimefrom a givenInstant.static LocalDateTimetoLocalDateTime(Date date) Converts the givenDateto aLocalDateTime.
-
Field Details
-
JSON_DATE_FORMAT
- See Also:
-
JSON_DATE_TIME_FORMAT
- See Also:
-
-
Constructor Details
-
DateTimeUtils
public DateTimeUtils()
-
-
Method Details
-
getDate
Returns a date.- Parameters:
year- the year.month- the month, from 1.dayOfMonth- , from 1 to 31.- Returns:
- a
Date.
-
getDateString
Returns a date string on the format:yyyy-MM-dd.- Parameters:
date- theDate.- Returns:
- a date string.
-
getLocalDate
Returns aLocalDatebased on the given string. The string must be on the ISO local date format, e.g.2007-12-03.- Parameters:
string- the date string.- Returns:
- a
LocalDate.
-
getLocalDateString
Returns a date string on the format:yyyy-MM-dd.- Parameters:
date- theLocalDate.- Returns:
- a date time string.
-
isValidLocalDate
Indicates whether the given string can be parsed to a local date, i.e. is in a valid ISO date format, e.g.2007-12-03.- Parameters:
string- the date string.- Returns:
- true if the given string can be parsed to a local date, false otherwise.
-
getLocalDateTime
Returns aLocalDateTimebased on the given string using the UTC time zone. The string must be on the ISO local date time format, e.g.2007-12-03T10:15:30.00or2007-12-03T10:15:30.00Z. A trailing 'Z' indicating Zulu/UTC time will be ignored.- Parameters:
string- the instant string.- Returns:
- a
LocalDateTime.
-
getLocalDateTimeAsDate
Returns aLocalDatebased on the given string using the UTC time zone. The string must be on the ISO local date time format, e.g.2007-12-03T10:15:30.00or2007-12-03T10:15:30.00Z. A trailing 'Z' indicating Zulu/UTC time will be ignored.- Parameters:
string- the instant string.- Returns:
- a
LocalDateTime.
-
isValidLocalDateTime
Indicates whether the given string can be parsed to a local date time, i.e. is in a valid ISO date time format, e.g.2007-12-03T10:15:30.00Z.- Parameters:
string- the instant string.- Returns:
- true if the given string can be parsed to a local date time, false otherwise.
-
getLocalDateTimeString
Returns a date time string on the format:yyyy-MM-dd'T'HH:mm:ss.SSS.- Parameters:
dateTime- theLocalDateTime.- Returns:
- a date time string.
-
getDateTimeString
Returns a date time string on the format:yyyy-MM-dd'T'HH:mm:ss.SSS.- Parameters:
dateTime- theDate.- Returns:
- a date time string.
-
getUtcDateTimeString
Returns a date time string on the format:yyyy-MM-dd'T'HH:mm:ss.SSSZ.- Parameters:
dateTime- theLocalDateTime.- Returns:
- a date time string.
-
getUtcDateTimeString
Returns a date time string on the format:yyyy-MM-dd'T'HH:mm:ss.SSSZ.- Parameters:
dateTime- theDate.- Returns:
- a date time string.
-
toInstant
Returns theInstantof received date param. if data is null, it also returns null Instant. -
toLocalDate
-
toLocalDateTime
Returns theLocalDateTimefrom a givenInstant.- Parameters:
instant- theInstant.- Returns:
- the
LocalDateTime.
-
toDate
-
toDate
Returns aDatefrom aLocalDateTime.- Parameters:
dateTime- theLocalDateTime.- Returns:
- the
Date.
-
toLocalDate
-
toLocalDateTime
Converts the givenDateto aLocalDateTime.- Parameters:
date- theDate.- Returns:
- a
LocalDateTime.
-