开发者

How to convert Facebook created_time to Java Date?

开发者 https://www.devze.com 2023-01-02 17:12 出处:网络
I have a FQL statement like this: String query = \"SELECT post_id, actor_id, target_id, created_time, messag开发者_StackOverflowe

I have a FQL statement like this:

String query = "SELECT post_id, actor_id, target_id, created_time, messag开发者_StackOverflowe 
FROM stream WHERE source_id in (SELECT target_id FROM connection 
WHERE source_id=<userID>) AND is_hidden = 0";

I just wondering what kind of time Facebook gives to me. The result of my statement will be mapped to a wrapper object (wallpost).

myDate.setTime(wallpost.getCreated_time());

gives me no valid date.

Does anyone have an idea what kind of date Facebook returns and how to match it to Date()?

thanks in advance!


This can have several causes. Two most possible are:

  1. The created_time is in seconds, while Date#setTime() expects milliseconds. Multiply it by 1000 before setting.

  2. The created_time represents the 24h clock rather than the epoch timestamp as Date is expecting. Append the timestamp of today on 00:00AM before setting.

To determine the one or other, do a

System.out.println(wallpost.getCreated_time()); 

and

System.out.println(myDate);

so that you can conclude yourself logically.


Solution: multiply the Facebook timestamp with 1000. Facebook saves seconds, not milliseconds.

this did the job:

myDate.setTime(wallpost.getCreated_time()*1000); 
0

精彩评论

暂无评论...
验证码 换一张
取 消