Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Convert Facebook created_time to UTC

I am using Facebook graph API to retrieve user wall information. In that, I am getting the post created time value as:

created_time: "2012-04-19T09:00:02+0000"

Can anyone suggest me how to convert this time to UTC or epoch value in Java?

like image 590
Venkat Avatar asked Dec 13 '22 03:12

Venkat


2 Answers

The format of date you receive is ISO 8601.

As described in Converting ISO8601-compliant String to java.util.Date (using Joda-Time):

DateTimeFormatter parser = ISODateTimeFormat.dateTimeNoMillis();
String jtdate = "2012-04-19T09:00:02+0000";
System.out.println(parser.parseDateTime(jtdate));
like image 109
Juicy Scripter Avatar answered Jan 19 '23 00:01

Juicy Scripter


You basically need to parse the ISO8601 date format. There are libraries out there that would do it for you or you can create your own parser (relatively simply), e.g.

http://www.java2s.com/Code/Java/Data-Type/ISO8601dateparsingutility.htm

like image 39
scibuff Avatar answered Jan 18 '23 22:01

scibuff