public final class DateUtils extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static java.util.GregorianCalendar |
calendar
A shared instance used for conversion between individual date fields
and long millis time.
|
private static java.util.GregorianCalendar |
calendarLocale |
static BooleanProperty |
PROP_ISO_DATES
Property to enable display of ISO dates globally.
|
private static javax.xml.datatype.DatatypeFactory |
XML_DATE |
Modifier | Constructor and Description |
---|---|
private |
DateUtils() |
Modifier and Type | Method and Description |
---|---|
private static boolean |
checkLayout(java.lang.String text,
java.lang.String pattern) |
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) |
protected static void |
setTimeZone(java.util.TimeZone zone)
Allows to override the timezone for unit tests.
|
private static java.lang.String |
toXmlFormat(java.util.GregorianCalendar cal) |
static long |
tsFromString(java.lang.String str)
Parses XML date quickly, regardless of current locale.
|
public static final BooleanProperty PROP_ISO_DATES
private static final java.util.GregorianCalendar calendar
private static final java.util.GregorianCalendar calendarLocale
private static final javax.xml.datatype.DatatypeFactory XML_DATE
private DateUtils()
public static java.util.Date fromString(java.lang.String str) throws UncheckedParseException
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) throws UncheckedParseException
str
- The XML date as stringUncheckedParseException
- if the date does not match any of the supported date formatsprivate static java.lang.String toXmlFormat(java.util.GregorianCalendar cal)
public 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 formatprivate 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 setprotected static void setTimeZone(java.util.TimeZone zone)
zone
- the timezone to use