Modifier and Type | Field and Description |
---|---|
private static GregorianCalendar |
calendar
A shared instance used for conversion between individual date fields
and long millis time.
|
static BooleanProperty |
PROP_ISO_DATES
Property to enable display of ISO dates globally.
|
private static DatatypeFactory |
XML_DATE |
Modifier | Constructor and Description |
---|---|
private |
DateUtils() |
Modifier and Type | Method and Description |
---|---|
private static boolean |
checkLayout(String text,
String pattern) |
static String |
formatDate(Date date,
int dateStyle)
Formats a date to be displayed to current user, based on user preferences.
|
static String |
formatDateTime(Date datetime,
int dateStyle,
int timeStyle)
Formats a date/time to be displayed to current user, based on user preferences.
|
static String |
formatTime(Date time,
int timeStyle)
Formats a time to be displayed to current user, based on user preferences.
|
static String |
fromDate(Date date)
Formats a date to the XML UTC format regardless of current locale.
|
static Date |
fromString(String str)
Parses XML date quickly, regardless of current locale.
|
static String |
fromTimestamp(int timestamp)
Formats a date to the XML UTC format regardless of current locale.
|
static DateFormat |
getDateFormat(int dateStyle)
Returns the date format to be used for current user, based on user preferences.
|
static DateFormat |
getDateTimeFormat(int dateStyle,
int timeStyle)
Returns the date/time format to be used for current user, based on user preferences.
|
static DateFormat |
getTimeFormat(int timeStyle)
Returns the time format to be used for current user, based on user preferences.
|
static SimpleDateFormat |
newIsoDateFormat()
Returns a new
SimpleDateFormat for date only, according to ISO 8601. |
static SimpleDateFormat |
newIsoDateTimeFormat()
Returns a new
SimpleDateFormat for date and time, according to ISO 8601. |
static 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(String str,
int off) |
private static int |
parsePart3(String str,
int off) |
private static int |
parsePart4(String str,
int off) |
private static String |
toXmlFormat(GregorianCalendar cal) |
static long |
tsFromString(String str)
Parses XML date quickly, regardless of current locale.
|
public static final BooleanProperty PROP_ISO_DATES
private static GregorianCalendar calendar
private static final DatatypeFactory XML_DATE
private DateUtils()
public static Date fromString(String str)
str
- The XML date as stringpublic static long tsFromString(String str)
str
- The XML date as stringprivate static String toXmlFormat(GregorianCalendar cal)
public static String fromTimestamp(int timestamp)
timestamp
- number of seconds since the epochpublic static String fromDate(Date date)
date
- The date to formatprivate static boolean checkLayout(String text, String pattern)
private static int num(char c)
private static int parsePart2(String str, int off)
private static int parsePart3(String str, int off)
private static int parsePart4(String str, int off)
public static SimpleDateFormat newIsoDateFormat()
SimpleDateFormat
for date only, according to ISO 8601.public static SimpleDateFormat newIsoDateTimeFormat()
SimpleDateFormat
for date and time, according to ISO 8601.public static SimpleDateFormat newOsmApiDateTimeFormat()
SimpleDateFormat
for date and time, according to format used in OSM API errors.public static DateFormat getDateFormat(int dateStyle)
dateStyle
- The date style as described in DateFormat.getDateInstance()
. Ignored if "ISO dates" option is setpublic static String formatDate(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 DateFormat getTimeFormat(int timeStyle)
timeStyle
- The time style as described in DateFormat.getTimeInstance()
. Ignored if "ISO dates" option is setpublic static String formatTime(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 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 String formatDateTime(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