What is the format of uploaded date of youtube api I can use in SimpleDateFormat?
example "2013-03-31T16:46:38.000Z
"
P.S. solution was found yyyy-MM-dd'T'HH:mm:ss.SSSX
thanks
It is a ISO 8061 date time
Actually, at least in Java8 it's very simple to parse that one as there is a predefined DateTimeFormatter
. Here a small unit test as demonstration:
import org.junit.Test;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import static org.junit.Assert.assertEquals;
public class DateTimeFormatterTest {
@Test
public void testIsoDateTimeParse() throws Exception {
// when
final ZonedDateTime dateTime = ZonedDateTime.parse("2013-03-31T16:46:38.000Z", DateTimeFormatter.ISO_DATE_TIME);
// then
assertEquals(2013, dateTime.getYear());
assertEquals(3, dateTime.getMonthValue());
assertEquals(31, dateTime.getDayOfMonth());
assertEquals(16, dateTime.getHour());
assertEquals(46, dateTime.getMinute());
assertEquals(38, dateTime.getSecond());
assertEquals(ZoneOffset.UTC, dateTime.getZone());
}
}
Prior to Java8, I would take a look at Converting ISO 8601-compliant String to java.util.Date and definitley default to using Joda Time with sth. like:
final org.joda.time.DateTime dateTime = new org.joda.time.DateTime.parse("2013-03-31T16:46:38.000Z");
BTW, don't use new DateTime("2013-03-31T16:46:38.000Z")
as it will use your default time zone, which is probably not what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With