Package com.google.gson.typeadapters
Class UtcDateTypeAdapter
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static boolean
checkOffset
(String value, int offset, char expected) Check if the expected character exist at the given offset in the value.private static String
Format date into yyyy-MM-ddThh:mm:ss[.sss][Z|[+-]hh:mm]private static void
padInt
(StringBuilder buffer, int value, int length) Zero pad a number to a specified lengthprivate static Date
parse
(String date, ParsePosition pos) Parse a date from ISO-8601 formatted string.private static int
Parse an integer located between 2 given offsets in a stringread
(JsonReader in) Reads one JSON value (an array, object, string, number, boolean or null) and converts it to a Java object.void
write
(JsonWriter out, Date date) Writes one JSON value (an array, object, string, number, boolean or null) forvalue
.Methods inherited from class com.google.gson.TypeAdapter
fromJson, fromJson, fromJsonTree, nullSafe, toJson, toJson, toJsonTree
-
Field Details
-
UTC_TIME_ZONE
-
GMT_ID
- See Also:
-
-
Constructor Details
-
UtcDateTypeAdapter
public UtcDateTypeAdapter()
-
-
Method Details
-
write
Description copied from class:TypeAdapter
Writes one JSON value (an array, object, string, number, boolean or null) forvalue
.- Specified by:
write
in classTypeAdapter<Date>
- Parameters:
date
- the Java object to write. May be null.- Throws:
IOException
-
read
Description copied from class:TypeAdapter
Reads one JSON value (an array, object, string, number, boolean or null) and converts it to a Java object. Returns the converted object.- Specified by:
read
in classTypeAdapter<Date>
- Returns:
- the converted Java object. May be null.
- Throws:
IOException
-
format
Format date into yyyy-MM-ddThh:mm:ss[.sss][Z|[+-]hh:mm]- Parameters:
date
- the date to formatmillis
- true to include millis precision otherwise falsetz
- timezone to use for the formatting (GMT will produce 'Z')- Returns:
- the date formatted as yyyy-MM-ddThh:mm:ss[.sss][Z|[+-]hh:mm]
-
padInt
Zero pad a number to a specified length- Parameters:
buffer
- buffer to use for paddingvalue
- the integer value to pad if necessary.length
- the length of the string we should zero pad
-
parse
Parse a date from ISO-8601 formatted string. It expects a format [yyyy-MM-dd|yyyyMMdd][T(hh:mm[:ss[.sss]]|hhmm[ss[.sss]])]?[Z|[+-]hh:mm]]- Parameters:
date
- ISO string to parse in the appropriate format.pos
- The position to start parsing from, updated to where parsing stopped.- Returns:
- the parsed date
- Throws:
ParseException
- if the date is not in the appropriate format
-
checkOffset
Check if the expected character exist at the given offset in the value.- Parameters:
value
- the string to check at the specified offsetoffset
- the offset to look for the expected characterexpected
- the expected character- Returns:
- true if the expected character exist at the given offset
-
parseInt
private static int parseInt(String value, int beginIndex, int endIndex) throws NumberFormatException Parse an integer located between 2 given offsets in a string- Parameters:
value
- the string to parsebeginIndex
- the start index for the integer in the stringendIndex
- the end index for the integer in the string- Returns:
- the int
- Throws:
NumberFormatException
- if the value is not a number
-