public class DateUtils
extends java.lang.Object
Date
instances as OpenAPI
"date" or "date-time" values.
Modifier and Type | Field and Description |
---|---|
static java.time.format.DateTimeFormatter |
rfc3339DateTimeFmt |
static java.time.format.DateTimeFormatter |
rfc3339FullDateFmt |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
formatAsDate(java.util.Date d)
Formats the specified
Date instance as an RFC 3339 "full-date" value (yyyy-MM-dd).The Date instance is assumed to represent the start of the specified day in UTC time. |
static java.lang.String |
formatAsDateTime(java.util.Date d)
Formats the specified
Date instance as an RFC 3339 "date-time" value
(a string of the form "yyyy-MM-dd'T'HH:mm:ss.SSSZ").The Date instance represents a moment in time (the number of milliseconds
since epoch time in UTC). |
static java.util.Date |
parseAsDate(java.lang.String s)
Parses the specified string (assumed to be of the form "yyyy-MM-dd") into a
Date instance. |
static java.util.Date |
parseAsDateTime(java.lang.String dateAsString)
Parses the specified string into a
Date instance. |
public static final java.time.format.DateTimeFormatter rfc3339FullDateFmt
public static final java.time.format.DateTimeFormatter rfc3339DateTimeFmt
public static java.lang.String formatAsDate(java.util.Date d)
Date
instance as an RFC 3339 "full-date" value (yyyy-MM-dd).Date
instance is assumed to represent the start of the specified day in UTC time.
No adjustment for timezone is performed while formatting the value.d
- the Date
instance to be formattedjava.time.DateTimeException
- if an error occurs during formattingpublic static java.lang.String formatAsDateTime(java.util.Date d)
Date
instance as an RFC 3339 "date-time" value
(a string of the form "yyyy-MM-dd'T'HH:mm:ss.SSSZ").Date
instance represents a moment in time (the number of milliseconds
since epoch time in UTC).d
- the Date
instance to be formattedjava.time.DateTimeException
- if an error occurs during formattingpublic static java.util.Date parseAsDate(java.lang.String s)
Date
instance.
Specifically, the string is parsed into a Date
instance that represents
the start of the specified day in UTC time.
This is aligned with the formatAsDate(java.util.Date)
method which formats the Date
instance
using "yyyy-MM-dd" without any adjustment for timezone.s
- the string to be parsedDate
valuejava.time.DateTimeException
- if an error occurs during parsingpublic static java.util.Date parseAsDateTime(java.lang.String dateAsString)
Date
instance.
The supported formats are:
dateAsString
- the string to be parsedDate
instancejava.time.DateTimeException
- if an error occurs during parsingCopyright © 2022 IBM Cloud Developer Experience. All rights reserved.