Class TmfTimestampFormat
- All Implemented Interfaces:
Serializable,Cloneable
The timestamp representation is broken down into a number of optional components that can be assembled into a fairly simple way.
Date and Time Patterns
All date and time pattern letters defined inSimpleDateFormat are
supported with the following exceptions:
Format Description Value Range Example TThe seconds since the epoch 0-92233720361332170682TdThe deciseconds since the epoch 0-9223372036813321706825TcThe centiseconds since the epoch 0-922337203685133217068253TmThe milliseconds since the epoch 0-92233720368541332170682539TuThe microseconds since the epoch 0-92233720368547751332170682539677TnThe nanoseconds since the epoch 0-92233720368547758071332170682539677389SMillisecond N/ANot supportedWWeek in month N/ANot supported
Note: When parsing, if "T" is used, no other Date and Time pattern letter will be interpreted and the entire pre-delimiter input string will be parsed as a number. Also, "T" should be used for time intervals.
Note: The decimal separator between the Date and Time pattern and the Sub-Seconds pattern is mandatory (if there is a fractional part) and must be one of the sub-second delimiters. Date and Time pattern letters are not interpreted after the decimal separator.
Sub-Seconds Patterns
Note: The fraction of second pattern can be split, in which case parsing and formatting continues at the next digit. Digits beyond the total number of pattern letters are ignored when parsing and truncated when formatting.
Format Description Value Range Example SFraction of second (or unit of second) 0-999999999123456789CMicroseconds in ms 0-999456NNanoseconds in µs 0-999789
Note: When parsing, "S", "C" and "N" are interchangeable and are all handled as fraction of second ("S"). The use of "C" and "N" is discouraged but is supported for backward compatibility.
The recognized sub-second delimiters are:
- Space ("
") - Period ("
.") - Comma ("
,") - Dash ("
-") - Underline ("
_") - Colon ("
:") - Semicolon ("
;") - Slash ("
/") - Single-quote ("
''") - Double-quote ("
"")
Note: When parsing, sub-second delimiters are optional if unquoted. However, an extra delimiter or any other unexpected character in the input string ends the parsing of digits. All other quoted or unquoted characters in the sub-second pattern are matched against the input string.
Examples
The following examples show how timestamp patterns are interpreted in the U.S. locale. The given timestamp is 1332170682539677389L, the number of nanoseconds since 1970/01/01.
Date and Time Pattern Result "yyyy-MM-dd HH:mm:ss.SSS.SSS.SSS"2012-03-19 11:24:42.539.677.389"yyyy-MM-dd HH:mm:ss.SSS.SSS"2012-03-19 11:24:42.539.677"yyyy-D HH:mm:ss.SSS.SSS"2012-79 11:24:42.539.677"ss,SSSS"42,5397"T.SSS SSS SSS"1332170682.539 677 389"T"1332170682"Tm.SSSSSS"1332170682539.677389"Tn"1332170682539677389
- Author:
- Francois Chouinard
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.text.DateFormat
DateFormat.Field -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe default interval patternstatic final StringThe default timestamp patternFields inherited from class java.text.DateFormat
AM_PM_FIELD, DATE_FIELD, DAY_OF_WEEK_FIELD, DAY_OF_WEEK_IN_MONTH_FIELD, DAY_OF_YEAR_FIELD, DEFAULT, ERA_FIELD, FULL, HOUR_OF_DAY0_FIELD, HOUR_OF_DAY1_FIELD, HOUR0_FIELD, HOUR1_FIELD, LONG, MEDIUM, MILLISECOND_FIELD, MINUTE_FIELD, MONTH_FIELD, SECOND_FIELD, SHORT, TIMEZONE_FIELD, WEEK_OF_MONTH_FIELD, WEEK_OF_YEAR_FIELD, YEAR_FIELD -
Constructor Summary
ConstructorsConstructorDescriptionThe default constructor (uses the default pattern)TmfTimestampFormat(@NonNull String pattern) The normal constructorTmfTimestampFormat(@NonNull String pattern, TimeZone timeZone) The full constructorTmfTimestampFormat(@NonNull String pattern, TimeZone timeZone, Locale locale) The fuller constructorThe copy constructor -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyPattern(String pattern) format(long value) Format the timestamp according to its pattern.static TmfTimestampFormatstatic TmfTimestampFormatlongparseValue(String source) Parse a string according to the format patternlongparseValue(String source, long ref) Parse a string according to the format pattern@NonNull Stringstatic voidUpdate the default time and default interval formatsMethods inherited from class java.text.SimpleDateFormat
applyLocalizedPattern, clone, equals, format, formatToCharacterIterator, get2DigitYearStart, getDateFormatSymbols, hashCode, parse, set2DigitYearStart, setDateFormatSymbols, toLocalizedPatternMethods inherited from class java.text.DateFormat
format, format, getAvailableLocales, getCalendar, getDateInstance, getDateInstance, getDateInstance, getDateTimeInstance, getDateTimeInstance, getDateTimeInstance, getInstance, getNumberFormat, getTimeInstance, getTimeInstance, getTimeInstance, getTimeZone, isLenient, parse, parseObject, setCalendar, setLenient, setNumberFormat, setTimeZoneMethods inherited from class java.text.Format
format, parseObject
-
Field Details
-
DEFAULT_TIME_PATTERN
The default timestamp pattern- See Also:
-
DEFAULT_INTERVAL_PATTERN
The default interval pattern- See Also:
-
-
Constructor Details
-
TmfTimestampFormat
public TmfTimestampFormat()The default constructor (uses the default pattern) -
TmfTimestampFormat
The normal constructor- Parameters:
pattern- the format pattern
-
TmfTimestampFormat
The full constructor- Parameters:
pattern- the format patterntimeZone- the time zone
-
TmfTimestampFormat
The fuller constructor- Parameters:
pattern- the format patterntimeZone- the time zonelocale- the locale
-
TmfTimestampFormat
The copy constructor- Parameters:
other- the other format pattern
-
-
Method Details
-
updateDefaultFormats
public static void updateDefaultFormats()Update the default time and default interval formats -
getDefaulTimeFormat
- Returns:
- the default time format pattern
-
getDefaulIntervalFormat
- Returns:
- the default interval format pattern
-
applyPattern
- Overrides:
applyPatternin classSimpleDateFormat
-
toPattern
- Overrides:
toPatternin classSimpleDateFormat
-
format
Format the timestamp according to its pattern.- Parameters:
value- the timestamp value to format (in ns)- Returns:
- the formatted timestamp
-
parseValue
Parse a string according to the format pattern- Parameters:
source- the source stringref- the reference (base) time (in ns)- Returns:
- the parsed value (in ns)
- Throws:
ParseException- if the string has an invalid format
-
parseValue
Parse a string according to the format pattern- Parameters:
source- the source string- Returns:
- the parsed value (in ns)
- Throws:
ParseException- if the string has an invalid format
-