Class DateUtils
java.lang.Object
org.openstreetmap.josm.tools.date.DateUtils
A static utility class dealing with:
- parsing XML date quickly and formatting a date to the XML UTC format regardless of current locale
- providing a single entry point for formatting dates to be displayed in JOSM GUI, based on user preferences
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final DateTimeFormatterDiffers fromDateTimeFormatter.ISO_LOCAL_DATE_TIMEby using ' ' instead of 'T' to separate date/time.static final BooleanPropertyProperty to enable display of ISO dates globally.static final TimeZoneThe UTC time zone. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static booleancheckLayout(String text, String pattern) Check text for a specified layoutstatic DateNull-safe date cloning method.static StringformatDate(Date date, int dateStyle) Formats a date to be displayed to current user, based on user preferences.static StringformatDateTime(Date datetime, int dateStyle, int timeStyle) Formats a date/time to be displayed to current user, based on user preferences.static StringformatTime(Date time, int timeStyle) Formats a time to be displayed to current user, based on user preferences.static StringFormats a date to the XML UTC format regardless of current locale.static DatefromString(String str) Parses XML date quickly, regardless of current locale.static StringfromTimestamp(int timestamp) Formats a date to the XML UTC format regardless of current locale.static StringfromTimestamp(long timestamp) Formats a date to the XML UTC format regardless of current locale.static StringfromTimestampInMillis(long timestamp) Formats a date to the XML UTC format regardless of current locale.static DateFormatgetDateFormat(int dateStyle) Returns the date format to be used for current user, based on user preferences.static DateTimeFormattergetDateFormatter(FormatStyle dateStyle) Returns the date formatter to be used for current user, based on user preferences.static DateFormatgetDateTimeFormat(int dateStyle, int timeStyle) Returns the date/time format to be used for current user, based on user preferences.static DateTimeFormattergetDateTimeFormatter(FormatStyle dateStyle, FormatStyle timeStyle) Returns the date/time formatter to be used for current user, based on user preferences.static DateFormatgetTimeFormat(int timeStyle) Returns the time format to be used for current user, based on user preferences.static DateTimeFormattergetTimeFormatter(FormatStyle timeStyle) Returns the time formatter to be used for current user, based on user preferences.static SimpleDateFormatReturns a newSimpleDateFormatfor date only, according to ISO 8601.private static intnum(char c) static InstantparseInstant(String str) Parses the given date string quickly, regardless of current locale.private static intparsePart2(String str, int off) private static intparsePart3(String str, int off) private static intparsePart4(String str, int off) private static intparsePart6(String str, int off) static longtsFromString(String str) Parses XML date quickly, regardless of current locale.
-
Field Details
-
UTC
The UTC time zone. -
PROP_ISO_DATES
Property to enable display of ISO dates globally.- Since:
- 7299
-
ISO_LOCAL_DATE_TIME
Differs fromDateTimeFormatter.ISO_LOCAL_DATE_TIMEby using ' ' instead of 'T' to separate date/time.
-
-
Constructor Details
-
DateUtils
private DateUtils()Constructs a newDateUtils.
-
-
Method Details
-
fromString
Parses XML date quickly, regardless of current locale.- Parameters:
str- The XML date as string- Returns:
- The date
- Throws:
UncheckedParseException- if the date does not match any of the supported date formatsDateTimeException- if the value of any field is out of range, or if the day-of-month is invalid for the month-year
-
tsFromString
Parses XML date quickly, regardless of current locale.- Parameters:
str- The XML date as string- Returns:
- The date in milliseconds since epoch
- Throws:
UncheckedParseException- if the date does not match any of the supported date formatsDateTimeException- if the value of any field is out of range, or if the day-of-month is invalid for the month-year
-
parseInstant
Parses the given date string quickly, regardless of current locale.- Parameters:
str- the date string- Returns:
- the parsed instant
- Throws:
UncheckedParseException- if the date does not match any of the supported date formats
-
fromTimestamp
Formats a date to the XML UTC format regardless of current locale.- Parameters:
timestamp- number of seconds since the epoch- Returns:
- The formatted date
- Since:
- 14055
-
fromTimestampInMillis
Formats a date to the XML UTC format regardless of current locale.- Parameters:
timestamp- number of milliseconds since the epoch- Returns:
- The formatted date
- Since:
- 14434
-
fromTimestamp
Formats a date to the XML UTC format regardless of current locale.- Parameters:
timestamp- number of seconds since the epoch- Returns:
- The formatted date
-
fromDate
Formats a date to the XML UTC format regardless of current locale.- Parameters:
date- The date to format- Returns:
- The formatted date
-
cloneDate
Null-safe date cloning method.- Parameters:
d- date to clone, or null- Returns:
- cloned date, or null
- Since:
- 11878
-
checkLayout
Check text for a specified layout- Parameters:
text- The text to checkpattern- The pattern to use- Returns:
trueif the layout matches, otherwisefalse
-
num
-
parsePart2
-
parsePart3
-
parsePart4
-
parsePart6
-
newIsoDateFormat
Returns a newSimpleDateFormatfor date only, according to ISO 8601.- Returns:
- a new ISO 8601 date format, for date only.
- Since:
- 7299
-
getDateFormat
Returns the date format to be used for current user, based on user preferences.- Parameters:
dateStyle- The date style as described inDateFormat.getDateInstance(). Ignored if "ISO dates" option is set- Returns:
- The date format
- Since:
- 7299
-
getDateFormatter
Returns the date formatter to be used for current user, based on user preferences.- Parameters:
dateStyle- The date style. Ignored if "ISO dates" option is set.- Returns:
- The date format
-
formatDate
Formats a date to be displayed to current user, based on user preferences.- Parameters:
date- The date to display. Must not benulldateStyle- The date style as described inDateFormat.getDateInstance(). Ignored if "ISO dates" option is set- Returns:
- The formatted date
- Since:
- 7299
-
getTimeFormat
Returns the time format to be used for current user, based on user preferences.- Parameters:
timeStyle- The time style as described inDateFormat.getTimeInstance(). Ignored if "ISO dates" option is set- Returns:
- The time format
- Since:
- 7299
-
getTimeFormatter
Returns the time formatter to be used for current user, based on user preferences.- Parameters:
timeStyle- The time style. Ignored if "ISO dates" option is set.- Returns:
- The time format
-
formatTime
Formats a time to be displayed to current user, based on user preferences.- Parameters:
time- The time to display. Must not benulltimeStyle- The time style as described inDateFormat.getTimeInstance(). Ignored if "ISO dates" option is set- Returns:
- The formatted time
- Since:
- 7299
-
getDateTimeFormat
Returns the date/time format to be used for current user, based on user preferences.- Parameters:
dateStyle- The date style as described inDateFormat.getDateTimeInstance(). Ignored if "ISO dates" option is settimeStyle- The time style as described inDateFormat.getDateTimeInstance. Ignored if "ISO dates" option is set- Returns:
- The date/time format
- Since:
- 7299
-
getDateTimeFormatter
Returns the date/time formatter to be used for current user, based on user preferences.- Parameters:
dateStyle- The date style. Ignored if "ISO dates" option is set.timeStyle- The time style. Ignored if "ISO dates" option is set.- Returns:
- The date/time format
-
formatDateTime
Formats a date/time to be displayed to current user, based on user preferences.- Parameters:
datetime- The date/time to display. Must not benulldateStyle- The date style as described inDateFormat.getDateTimeInstance(). Ignored if "ISO dates" option is settimeStyle- The time style as described inDateFormat.getDateTimeInstance. Ignored if "ISO dates" option is set- Returns:
- The formatted date/time
- Since:
- 7299
-