
public final class UtcDateTypeAdapter extends TypeAdapter<Date>
| Modifier and Type | Field and Description |
|---|---|
private static String |
GMT_ID |
private TimeZone |
UTC_TIME_ZONE |
| Constructor and Description |
|---|
UtcDateTypeAdapter() |
| Modifier and Type | Method and Description |
|---|---|
private 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 date,
boolean millis,
TimeZone tz)
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 length
|
private static Date |
parse(String date,
ParsePosition pos)
Parse a date from ISO-8601 formatted string.
|
private static int |
parseInt(String value,
int beginIndex,
int endIndex)
Parse an integer located between 2 given offsets in a string
|
Date |
read(JsonReader in) |
void |
write(JsonWriter out,
Date date) |
fromJson, fromJson, fromJsonTree, nullSafe, toJson, toJson, toJsonTreeprivate final TimeZone UTC_TIME_ZONE
private static final String GMT_ID
public void write(JsonWriter out, Date date) throws IOException
write in class TypeAdapter<Date>IOExceptionpublic Date read(JsonReader in) throws IOException
read in class TypeAdapter<Date>IOExceptionprivate static String format(Date date, boolean millis, TimeZone tz)
date - the date to formatmillis - true to include millis precision otherwise falsetz - timezone to use for the formatting (GMT will produce 'Z')private static void padInt(StringBuilder buffer, int value, int length)
buffer - buffer to use for paddingvalue - the integer value to pad if necessary.length - the length of the string we should zero padprivate static Date parse(String date, ParsePosition pos) throws ParseException
date - ISO string to parse in the appropriate format.pos - The position to start parsing from, updated to where parsing stopped.ParseException - if the date is not in the appropriate formatprivate static boolean checkOffset(String value, int offset, char expected)
value - the string to check at the specified offsetoffset - the offset to look for the expected characterexpected - the expected characterprivate static int parseInt(String value, int beginIndex, int endIndex) throws NumberFormatException
value - the string to parsebeginIndex - the start index for the integer in the stringendIndex - the end index for the integer in the stringNumberFormatException - if the value is not a number