@Test public void testParseDate_Time() throws ParseException { RFC3339DateFormat format = new RFC3339DateFormat(); Date date = format.parse("2013-02-07"); assertEquals( 1360195200000L, date.getTime()); // Unix timestamp created with http://www.unixtimestamp.com/index.php }
@Test public void testParseDateTime_NoTime() throws ParseException { RFC3339DateFormat format = new RFC3339DateFormat(false); Date date = format.parse("2013-02-07T02:29:08.123Z"); assertEquals( 1360204148123L, date.getTime()); // Unix timestamp created with http://www.unixtimestamp.com/index.php }
@Test public void testParseTimezoneShiftDays() throws Exception { RFC3339DateFormat format = new RFC3339DateFormat(); Date date = format.parse("2013-02-06T21:29:08-05:00"); assertEquals( 1360204148000L, date.getTime()); // Unix timestamp created with http://www.unixtimestamp.com/index.php }
@Test public void testParseNoTZ() throws Exception { RFC3339DateFormat format = new RFC3339DateFormat(); Date date = format.parse("2014-01-06T17:45:01"); assertEquals( 1389030301000L, date.getTime()); // Unix timestamp created with http://www.unixtimestamp.com/index.php }
@Test public void testFormatWithMillis_NY() throws ParseException { RFC3339DateFormat format = new RFC3339DateFormat(TimeZone.getTimeZone("America/New_York")); String formatted = format.format(new Date(1360204148123L)); assertEquals("2013-02-06T21:29:08.123-05:00", formatted); }
@Test public void testFormatWithMillis() throws ParseException { RFC3339DateFormat format = new RFC3339DateFormat(); String formatted = format.format(new Date(1360204148123L)); assertEquals("2013-02-07T02:29:08.123Z", formatted); }
@Test public void testFormatNoTime() throws ParseException { RFC3339DateFormat format = new RFC3339DateFormat(false); String formatted = format.format(new Date(1360204148123L)); assertEquals("2013-02-07", formatted); }