Code example for SimpleDateFormat

Methods: parse

0
    public void testPreHistoricInDaylightTime() throws Exception { 
        TimeZone tz = TimeZone.getTimeZone("America/Los_Angeles");
        TimeZone.setDefault(tz);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
        Date date = sdf.parse("1902-11-01T00:00:00.000+0800");
        assertEquals(-2119680000000L, date.getTime());
        assertEquals(-28800000, tz.getOffset(date.getTime()));
        assertFalse(tz.inDaylightTime(date));
        assertEquals("Fri Oct 31 08:00:00 PST 1902", date.toString());
        assertEquals("31 Oct 1902 16:00:00 GMT", date.toGMTString());
        // Any time before we have transition data is considered non-daylight, even in summer. 
        date = sdf.parse("1902-06-01T00:00:00.000+0800");
        assertEquals(-28800000, tz.getOffset(date.getTime()));
        assertFalse(tz.inDaylightTime(date));
    } 
 
    public void testPreHistoricOffsets() throws Exception { 
        // The "Asia/Saigon" time zone has just a few transitions, and hasn't changed in a 
        // long time, which is convenient for testing: 
        // 
        // libcore.util.ZoneInfo[Asia/Saigon,mRawOffset=25200000,mUseDst=false]