Package loci.common
Class DateTools
java.lang.Object
loci.common.DateTools
A utility class with convenience methods for working with dates.
- Author:
- Curtis Rueden ctrueden at wisc.edu, Chris Allan callan at blackcat.ca, Melissa Linkert melissa at glencoesoftware.com
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final longstatic final intstatic final longstatic final StringHuman readable timestamp filename stringstatic final StringISO 8601 date output formatter without milliseconds.static final StringISO 8601 date output formatter with milliseconds.static final intstatic final longstatic final StringHuman readable timestamp stringstatic final intTimestamp formats.static final longMilliseconds until UNIX epoch.static final intstatic final long -
Method Summary
Modifier and TypeMethodDescriptionstatic StringconvertDate(long stamp, int format) Converts the given timestamp into an ISO8601 date.static StringconvertDate(long stamp, int format, String outputFormat) Converts the given timestamp into a date string with the given format.static StringconvertDate(long stamp, int format, String outputFormat, boolean correctTimeZoneForGMT) Converts the given timestamp into a date string with the given format.static StringformatDate(String date, String format) Formats the given date as an ISO 8601 date.static StringformatDate(String date, String[] formats) Formats the given date as an ISO 8601 date.static StringformatDate(String date, String[] formats, boolean lenient) Formats the given date as an ISO 8601 date.static StringformatDate(String date, String[] formats, boolean lenient, String separator) Formats the given date as an ISO 8601 date.static StringformatDate(String date, String[] formats, String separator) Formats the given date as an ISO 8601 date.static StringformatDate(String date, String format, boolean lenient) Formats the given date as an ISO 8601 date.static StringformatDate(String date, String format, boolean lenient, String separator) Formats the given date as an ISO 8601 date.static StringformatDate(String date, String format, String separator) Formats the given date as an ISO 8601 date.static Stringstatic longgetMillisFromTicks(long hi, long lo) Converts from two-word tick representation to milliseconds.static longConverts a string date in the given format to a long timestamp (in Unix format: milliseconds since January 1, 1970).static longConverts a string date in the given format to a long timestamp (in Unix format: milliseconds since January 1, 1970) with special milliseconds handling.static Stringprotected static org.joda.time.InstantParse the given date as a Joda instant
-
Field Details
-
UNIX
public static final int UNIXTimestamp formats.- See Also:
-
COBOL
public static final int COBOL- See Also:
-
MICROSOFT
public static final int MICROSOFT- See Also:
-
ZVI
public static final int ZVI- See Also:
-
ALT_ZVI
public static final int ALT_ZVI- See Also:
-
UNIX_EPOCH
public static final long UNIX_EPOCHMilliseconds until UNIX epoch.- See Also:
-
COBOL_EPOCH
public static final long COBOL_EPOCH- See Also:
-
MICROSOFT_EPOCH
public static final long MICROSOFT_EPOCH- See Also:
-
ZVI_EPOCH
public static final long ZVI_EPOCH- See Also:
-
ALT_ZVI_EPOCH
public static final long ALT_ZVI_EPOCH- See Also:
-
ISO8601_FORMAT_MS
ISO 8601 date output formatter with milliseconds.- See Also:
-
ISO8601_FORMAT
ISO 8601 date output formatter without milliseconds.- See Also:
-
TIMESTAMP_FORMAT
Human readable timestamp string- See Also:
-
FILENAME_FORMAT
Human readable timestamp filename string- See Also:
-
-
Method Details
-
getMillisFromTicks
public static long getMillisFromTicks(long hi, long lo) Converts from two-word tick representation to milliseconds. Mainly useful in conjunction with COBOL date conversion.- Parameters:
hi- the upper 32 bits of the tick countlo- the lower 32 bits of the tick count- Returns:
- the number of milliseconds corresponding to the tick count, where 1 tick = 100 ns
-
convertDate
Converts the given timestamp into an ISO8601 date.- Parameters:
stamp- the format-dependent timestamp in millisecondsformat- the format in whichstampis stored. This is used to select the epoch value used for normalizing the timestamp to milliseconds since the UNIX epoch. Valid values are #UNIX, #COBOL, #MICROSOFT, #ZVI, and #ALT_ZVI.- Returns:
- an ISO 8601 formatted timestamp
- See Also:
-
convertDate
Converts the given timestamp into a date string with the given format.- Parameters:
stamp- the format-dependent timestamp in millisecondsformat- the format in whichstampis stored. This is used to select the epoch value used for normalizing the timestamp to milliseconds since the UNIX epoch. Valid values are #UNIX, #COBOL, #MICROSOFT, #ZVI, and #ALT_ZVI.outputFormat- the pattern used for formatting the timestamp- Returns:
- a timestamp in the specified output format
- See Also:
-
UNIX_EPOCHCOBOL_EPOCHMICROSOFT_EPOCHZVI_EPOCHALT_ZVI_EPOCHDateTimeFormat
-
convertDate
public static String convertDate(long stamp, int format, String outputFormat, boolean correctTimeZoneForGMT) Converts the given timestamp into a date string with the given format. If correctTimeZoneForGMT is set, then the timestamp will be interpreted as being relative to GMT and not the local time zone.- Parameters:
stamp- the format-dependent timestamp in millisecondsformat- the format in whichstampis stored. This is used to select the epoch value used for normalizing the timestamp to milliseconds since the UNIX epoch. Valid values are #UNIX, #COBOL, #MICROSOFT, #ZVI, and #ALT_ZVI.outputFormat- the pattern used for formatting the timestampcorrectTimeZoneForGMT- true if the timestamp is relative to GMT- Returns:
- a timestamp in the specified output format
- See Also:
-
UNIX_EPOCHCOBOL_EPOCHMICROSOFT_EPOCHZVI_EPOCHALT_ZVI_EPOCHDateTimeFormat
-
parseDate
Parse the given date as a Joda instant- Parameters:
date- The date to parse as a Joda timestampformat- The date format to parse the string dateseparator- The separator for milliseconds- Returns:
- the Joda Instant object representing the timestamp
- See Also:
-
Instant
-
formatDate
Formats the given date as an ISO 8601 date. Delegates toformatDate(String, String, boolean), with thelenientflag set to false.- Parameters:
date- The date to format as ISO 8601format- The date format to parse the string date- Returns:
- an ISO 8601 formatted timestamp
-
formatDate
Formats the given date as an ISO 8601 date. Delegates toformatDate(String, String, boolean, String)with thelenientflag set to false.- Parameters:
date- The date to format as ISO 8601format- The date format to parse the string dateseparator- The separator for milliseconds- Returns:
- an ISO 8601 formatted timestamp
-
formatDate
Formats the given date as an ISO 8601 date.- Parameters:
date- The date to format as ISO 8601.format- The date format to parse the string datelenient- Whether or not to leniently parse the date.- Returns:
- an ISO 8601 formatted timestamp
-
formatDate
Formats the given date as an ISO 8601 date.- Parameters:
date- The date to format as ISO 8601format- The date format to parse the string datelenient- Whether or not to leniently parse the date.separator- The separator for milliseconds- Returns:
- an ISO 8601 formatted timestamp
-
formatDate
Formats the given date as an ISO 8601 date. Delegates toformatDate(String, String[], boolean, String)withlenientset to false andseparatorset to null.- Parameters:
date- The date to format as ISO 8601formats- The date possible formats to parse the string date- Returns:
- an ISO 8601 formatted timestamp
-
formatDate
Formats the given date as an ISO 8601 date. Delegates toformatDate(String, String[], boolean, String)withseparatorset to null.- Parameters:
date- The date to format as ISO 8601.formats- The date possible formats to parse the string datelenient- Whether or not to leniently parse the date.- Returns:
- an ISO 8601 formatted timestamp
-
formatDate
Formats the given date as an ISO 8601 date. Delegates toformatDate(String, String[], boolean, String)withlenientset to false.- Parameters:
date- The date to format as ISO 8601formats- The date possible formats to parse the string dateseparator- The separator for milliseconds- Returns:
- an ISO 8601 formatted timestamp
-
formatDate
Formats the given date as an ISO 8601 date.- Parameters:
date- The date to format as ISO 8601.formats- The date possible formats to parse the string datelenient- Whether or not to leniently parse the date.separator- The separator for milliseconds- Returns:
- an ISO 8601 formatted timestamp
-
getTime
Converts a string date in the given format to a long timestamp (in Unix format: milliseconds since January 1, 1970).- Parameters:
date- The date to convertformat- The date format to parse the string date- Returns:
- The date in milliseconds
-
getTime
Converts a string date in the given format to a long timestamp (in Unix format: milliseconds since January 1, 1970) with special milliseconds handling.- Parameters:
date- The date to convertformat- The date format to parse the string dateseparator- The separator for milliseconds- Returns:
- The date in milliseconds
-
getTimestamp
- Returns:
- a timestamp for the current timezone in a human-readable locale-independent format ("YYYY-MM-DD HH:MM:SS")
-
getFileTimestamp
- Returns:
- a timestamp for the current timezone in a format suitable for a filename in a locale-independent format ("YYYY-MM-DD_HH-MM-SS")
-