public class TimeFormat extends Object
Modifier and Type | Field and Description |
---|---|
static TimeFormat |
DEFAULT
An instance of TimeFormat that corresponds to default timezone as returned by
TimeZone.getDefault() method. |
static TimeFormat |
GMT
An instance of TimeFormat that corresponds to GMT timezone as returned by
TimeZone.getTimeZone("GMT") . |
Modifier and Type | Method and Description |
---|---|
TimeFormat |
asFullIso()
Returns TimeFormat instance that produces full ISO8610 string of "yyyy-MM-dd'T'HH:mm:ss.SSSX".
|
String |
format(Date time)
Converts
Date object into string according to the format like yyyyMMdd-HHmmss. |
String |
format(long time)
|
static TimeFormat |
getInstance(TimeZone timezone)
Returns TimeFormat instance for a specified timezone.
|
TimeZone |
getTimeZone()
Returns timezone of this TimeFormat instance.
|
Date |
parse(String value)
Reads Date from String.
|
static void |
setDefaultTimeZone(TimeZone timezone)
Changes time zone for
DEFAULT instance on the current and new threads. |
TimeFormat |
withMillis()
Returns TimeFormat instance that also includes milliseconds into string when using
format method. |
TimeFormat |
withTimeZone()
Returns TimeFormat instance that also includes timezone into string when using
format method. |
public static final TimeFormat DEFAULT
TimeZone.getDefault()
method.public static final TimeFormat GMT
TimeZone.getTimeZone("GMT")
.public static TimeFormat getInstance(TimeZone timezone)
timezone
- timezone for TimeFormat.NullPointerException
- if timezone is null.public static void setDefaultTimeZone(TimeZone timezone)
DEFAULT
instance on the current and new threads.
This method is not thread-safe. It is designed for use in unit-tests only.
Do not use this method in production code. It prints warning to the log when used.public TimeFormat withTimeZone()
format
method.public TimeFormat withMillis()
format
method.public TimeFormat asFullIso()
public Date parse(String value) throws InvalidFormatException, NullPointerException
TimePeriod.valueOf(String)
.
SimpleDateFormat
.
value
- String value to parse.InvalidFormatException
- if value has wrong format.NullPointerException
- if value == null.SimpleDateFormat
public String format(Date time) throws NullPointerException
Date
object into string according to the format like yyyyMMdd-HHmmss.
When withTimeZone()
was used to acquire this TimeFormat
instance,
then time zone is also included and formatted according to RFC 822 format (for example "+0300").
When withMillis()
was used to acquire this TimeFormat
instance,
the milliseconds are also included as .sss.
When time.getTime() == 0
this method returns string "0".
time
- date and time to format.NullPointerException
- if time is null.public String format(long time)
public TimeZone getTimeZone()
Copyright © 2017 Devexperts. All Rights Reserved.