public class TimeUtils extends Object
Provides utility methods related to dates / times.
Modifier and Type | Field and Description |
---|---|
static String |
ISO_8601_DATE_FORMAT
Defines the default string format for dates.
|
static String |
ISO_8601_DATE_TIME_FORMAT
Defines the default string format for date/time timestamps.
|
static int |
ISO_8601_DATE_TIME_FORMAT_LENGTH |
static ZoneId |
UTC
The UTC timezone.
|
Modifier and Type | Method and Description |
---|---|
static Instant |
dateToInstant(Date date)
|
static String |
formatUtcDate(Instant instant)
Formats an instant to a UTC date using the default date pattern
ISO_8601_DATE_FORMAT . |
static String |
formatUtcDateTime(Instant instant)
Formats an instant to a UTC date/time using the default date/time pattern
ISO_8601_DATE_TIME_FORMAT . |
static String |
formatUtcDateTime(Instant instant,
String pattern)
Formats the instant to a UTC date/time using the given pattern.
|
static Date |
instantToDate(Instant instant)
|
static Instant |
parseUtcDate(String text)
Parses a date string using the default date pattern
ISO_8601_DATE_FORMAT . |
static Instant |
parseUtcDateTime(String text)
Parses a date/time string using the default date/time pattern
ISO_8601_DATE_TIME_FORMAT . |
static Instant |
parseUtcDateTime(String text,
String pattern)
Parses a date/time string using the given pattern.
|
public static final ZoneId UTC
The UTC timezone.
public static final String ISO_8601_DATE_FORMAT
Defines the default string format for dates.
public static final String ISO_8601_DATE_TIME_FORMAT
Defines the default string format for date/time timestamps.
public static final int ISO_8601_DATE_TIME_FORMAT_LENGTH
public static String formatUtcDate(Instant instant)
Formats an instant to a UTC date using the default date pattern ISO_8601_DATE_FORMAT
.
instant
- the Instant
to be formattedDateTimeParseException
- if the operation failedpublic static Instant parseUtcDate(String text)
Parses a date string using the default date pattern ISO_8601_DATE_FORMAT
.
text
- the string to be parsedInstant
DateTimeParseException
- if the operation failedpublic static String formatUtcDateTime(Instant instant)
Formats an instant to a UTC date/time using the default date/time pattern ISO_8601_DATE_TIME_FORMAT
.
instant
- the Instant
to be formattedpublic static String formatUtcDateTime(Instant instant, String pattern)
Formats the instant to a UTC date/time using the given pattern.
instant
- the Instant
to be formattedpattern
- the pattern (see DateTimeFormatter.ofPattern(String)
)DateTimeParseException
- if the operation failedpublic static Instant parseUtcDateTime(String text)
Parses a date/time string using the default date/time pattern ISO_8601_DATE_TIME_FORMAT
.
text
- the string to be parsedDateTimeParseException
- if the operation failedIllegalArgumentException
- if the input has the wrong lengthpublic static Instant parseUtcDateTime(String text, String pattern)
Parses a date/time string using the given pattern.
text
- the string to be parsedInstant
DateTimeParseException
- if the operation failedpublic static Instant dateToInstant(Date date)
date
- the date valueCopyright © 2010 - 2018 edorasware ag. All Rights Reserved.