Class DateTimeUtil
java.lang.Object
com.bluebell.greenhouse.platform.util.datetime.DateTimeUtil
Handles manipulating dates & times.
- Version:
- 1.0.12
- Author:
- Stephen Prizio
-
Method Summary
Modifier and TypeMethodDescriptionstatic LocalDateTimeconvertToUtc(LocalDateTime localDateTime, ZoneId fromZoneId) Converts the given local date time to utc.static StringformatDuration(long totalSeconds) Formats a duration of time in seconds into a broken down format of Xd Xh Xm Xs.static LocalDateTimegetDateTimeInUtcForStringAndZone(String parse, String format, ZoneId fromZoneId) Converts an iso date time string into utc time.static LocalDateTimeTakes a string with zone offset info and parses it into a utc date time.static LocalDateTimegetDateTimeInZoneForUtcDateTime(LocalDateTime utcDateTime, ZoneId toZoneId) Converts a utc date time into the specified zone's date & time.Returns a list of supported time zones in bluebell.static booleanisDateWithinInterval(LocalDateTime compare, LocalDateTime start, LocalDateTime end) Returns true if the compare date is within the start and end date.static booleanisValidTimeZone(String timeZone) Validates the given time zone string.static LocalDateTimenow()Returns the current date & time, offset to the system-configured time zone.static LocalDateTimeReturns the current date & time, offset to the given timezone.static LocalDateTimeparseIsoDateOrDateTime(String parse) Parses an ISO-8601 date, local date-time, or offset-aware date-time into aLocalDateTime.static longtoUnixTimestamp(LocalDate localDate) Converts the givenLocalDateinto a unix timestamp using UTC midnight.static longtoUnixTimestamp(LocalDate localDate, ZoneId zoneId) static longtoUnixTimestamp(LocalDateTime localDateTime) Converts the givenLocalDateTimeinto a unix timestamp assuming UTC.static longtoUnixTimestamp(LocalDateTime localDateTime, ZoneId zoneId) Converts the givenLocalDateTimeinto a unix timestamp using the providedZoneId.
-
Method Details
-
getSupportedTimeZones
-
isValidTimeZone
-
now
Returns the current date & time, offset to the system-configured time zone.- Returns:
LocalDateTime
-
now
Returns the current date & time, offset to the given timezone.- Parameters:
zoneId-ZoneId- Returns:
LocalDateTime
-
convertToUtc
Converts the given local date time to utc.- Parameters:
localDateTime-LocalDateTimefromZoneId-ZoneId- Returns:
- local date time in utc
-
isDateWithinInterval
public static boolean isDateWithinInterval(LocalDateTime compare, LocalDateTime start, LocalDateTime end) Returns true if the compare date is within the start and end date.- Parameters:
compare- compare date & timestart- start intervalend- end interval- Returns:
- true if date is within the interval
-
getDateTimeInUtcForStringAndZone
public static LocalDateTime getDateTimeInUtcForStringAndZone(String parse, String format, ZoneId fromZoneId) Converts an iso date time string into utc time.- Parameters:
parse- string to parseformat- date time formatfromZoneId-ZoneId- Returns:
LocalDateTime
-
getDateTimeInZoneForUtcDateTime
public static LocalDateTime getDateTimeInZoneForUtcDateTime(LocalDateTime utcDateTime, ZoneId toZoneId) Converts a utc date time into the specified zone's date & time.- Parameters:
utcDateTime- the UTC date timetoZoneId-ZoneId- Returns:
LocalDateTime
-
getDateTimeInUtcForZoneAwareString
Takes a string with zone offset info and parses it into a utc date time.- Parameters:
parse- string to parse- Returns:
LocalDateTime
-
parseIsoDateOrDateTime
Parses an ISO-8601 date, local date-time, or offset-aware date-time into aLocalDateTime. Offset-aware values are normalized to UTC while date-only values are converted to the start of day.- Parameters:
parse- string to parse- Returns:
- parsed
LocalDateTime
-
toUnixTimestamp
-
toUnixTimestamp
-
toUnixTimestamp
Converts the givenLocalDateTimeinto a unix timestamp assuming UTC.- Parameters:
localDateTime-LocalDateTime- Returns:
- unix timestamp in seconds
-
toUnixTimestamp
Converts the givenLocalDateTimeinto a unix timestamp using the providedZoneId.- Parameters:
localDateTime-LocalDateTimezoneId-ZoneId- Returns:
- unix timestamp in seconds
-
formatDuration
Formats a duration of time in seconds into a broken down format of Xd Xh Xm Xs.- Parameters:
totalSeconds- duration in seconds- Returns:
- ex: 2d 4h 6m 8s
-