How do I convert a string of ISO-8601 datetime (ex: 2012-05-31T13:48:04Z
) to number of seconds( 10 digit integer
) using Java?
try this way
String DateStr="2012-05-31T13:48:04Z";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
Date d=sdf.parse(DateStr);
System.out.println(d.getTime());
output 1338452284000
From the comments of OP getTime() returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.Source