public final class DateUtils extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static BooleanProperty |
PROP_ISO_DATES
Property to enable display of ISO dates globally.
|
static java.util.TimeZone |
UTC
The UTC time zone.
|
private static javax.xml.datatype.DatatypeFactory |
XML_DATE |
Modifier | Constructor and Description |
---|---|
private |
DateUtils()
Constructs a new
DateUtils . |
Modifier and Type | Method and Description |
---|---|
private static boolean |
checkLayout(java.lang.String text,
java.lang.String pattern) |
static java.util.Date |
cloneDate(java.util.Date d)
Null-safe date cloning method.
|
static java.lang.String |
formatDate(java.util.Date date,
int dateStyle)
Formats a date to be displayed to current user, based on user preferences.
|
static java.lang.String |
formatDateTime(java.util.Date datetime,
int dateStyle,
int timeStyle)
Formats a date/time to be displayed to current user, based on user preferences.
|
static java.lang.String |
formatTime(java.util.Date time,
int timeStyle)
Formats a time to be displayed to current user, based on user preferences.
|
static java.lang.String |
fromDate(java.util.Date date)
Formats a date to the XML UTC format regardless of current locale.
|
static java.util.Date |
fromString(java.lang.String str)
Parses XML date quickly, regardless of current locale.
|
static java.lang.String |
fromTimestamp(int timestamp)
Formats a date to the XML UTC format regardless of current locale.
|
static java.text.DateFormat |
getDateFormat(int dateStyle)
Returns the date format to be used for current user, based on user preferences.
|
static java.text.DateFormat |
getDateTimeFormat(int dateStyle,
int timeStyle)
Returns the date/time format to be used for current user, based on user preferences.
|
static java.text.DateFormat |
getTimeFormat(int timeStyle)
Returns the time format to be used for current user, based on user preferences.
|
static java.text.SimpleDateFormat |
newIsoDateFormat()
Returns a new
SimpleDateFormat for date only, according to ISO 8601. |
static java.text.SimpleDateFormat |
newIsoDateTimeFormat()
Returns a new
SimpleDateFormat for date and time, according to ISO 8601. |
static java.text.SimpleDateFormat |
newOsmApiDateTimeFormat()
Returns a new
SimpleDateFormat for date and time, according to format used in OSM API errors. |
private static int |
num(char c) |
private static int |
parsePart2(java.lang.String str,
int off) |
private static int |
parsePart3(java.lang.String str,
int off) |
private static int |
parsePart4(java.lang.String str,
int off) |
static long |
tsFromString(java.lang.String str)
Parses XML date quickly, regardless of current locale.
|
public static final java.util.TimeZone UTC
public static final BooleanProperty PROP_ISO_DATES
private static final javax.xml.datatype.DatatypeFactory XML_DATE
private DateUtils()
DateUtils
.public static java.util.Date fromString(java.lang.String str)
str
- The XML date as stringUncheckedParseException
- if the date does not match any of the supported date formatspublic static long tsFromString(java.lang.String str)
str
- The XML date as stringUncheckedParseException
- if the date does not match any of the supported date formatspublic static java.lang.String fromTimestamp(int timestamp)
timestamp
- number of seconds since the epochpublic static java.lang.String fromDate(java.util.Date date)
date
- The date to formatpublic static java.util.Date cloneDate(java.util.Date d)
d
- date to clone, or nullprivate static boolean checkLayout(java.lang.String text, java.lang.String pattern)
private static int num(char c)
private static int parsePart2(java.lang.String str, int off)
private static int parsePart3(java.lang.String str, int off)
private static int parsePart4(java.lang.String str, int off)
public static java.text.SimpleDateFormat newIsoDateFormat()
SimpleDateFormat
for date only, according to ISO 8601.public static java.text.SimpleDateFormat newIsoDateTimeFormat()
SimpleDateFormat
for date and time, according to ISO 8601.public static java.text.SimpleDateFormat newOsmApiDateTimeFormat()
SimpleDateFormat
for date and time, according to format used in OSM API errors.public static java.text.DateFormat getDateFormat(int dateStyle)
dateStyle
- The date style as described in DateFormat.getDateInstance()
. Ignored if "ISO dates" option is setpublic static java.lang.String formatDate(java.util.Date date, int dateStyle)
date
- The date to display. Must not be null
dateStyle
- The date style as described in DateFormat.getDateInstance()
. Ignored if "ISO dates" option is setpublic static java.text.DateFormat getTimeFormat(int timeStyle)
timeStyle
- The time style as described in DateFormat.getTimeInstance()
. Ignored if "ISO dates" option is setpublic static java.lang.String formatTime(java.util.Date time, int timeStyle)
time
- The time to display. Must not be null
timeStyle
- The time style as described in DateFormat.getTimeInstance()
. Ignored if "ISO dates" option is setpublic static java.text.DateFormat getDateTimeFormat(int dateStyle, int timeStyle)
dateStyle
- The date style as described in DateFormat.getDateTimeInstance()
. Ignored if "ISO dates" option is settimeStyle
- The time style as described in DateFormat.getDateTimeInstance
. Ignored if "ISO dates" option is setpublic static java.lang.String formatDateTime(java.util.Date datetime, int dateStyle, int timeStyle)
datetime
- The date/time to display. Must not be null
dateStyle
- The date style as described in DateFormat.getDateTimeInstance()
. Ignored if "ISO dates" option is settimeStyle
- The time style as described in DateFormat.getDateTimeInstance
. Ignored if "ISO dates" option is set