Odd question, but you have to know first that Facebook API defines all the dates with a timestamp (long = number of second) started 01/01/1970 00:00:00 located on PDT timezone (Pacifica time).
This number of second is not a UTC timestamp but a fake one based on a non-standard location.
Is there a simple way in java to convert this long timestamp to a normal Date object I could use (and print in french format with standard date formaters) ?
PS : It is not just a +7 hours question, daylight savings are included in this timestamp. In addition, we have also daylight saving in France but not the same ones…
Thanks
UPDATE :
It is more complicated that just à fixed delta.
I think Facebook records the date I give as a PSD date. If I record Thursday 26/10/2011 16H00 (Paris Timezone), Facebook records 26/10/2011 16H00 (San Francisco Timezone) and converts it to the appropriate number of second UTC since 1970. The problem is that this convertion takes into account daylight savings in San Francisco.
I did the following benchmark to demonstrate it :
- (31/12/2011 16:00 – France Time) FB Timestamp = 1325376000 instead of 1325343600 (Timestamp UTC) -> Delta : -32400
- (31/07/2012 16:00 – France Time) FB Timestamp = 1343775600 instead of 1343743200 -> Delta : -32400
- (03/10/2012 16:00 – France Time) FB Timestamp = 1349305200 instead of 1349272800 -> Delta : -32400
- (28/10/2012 08:00 – France Time) FB Timestamp = 1351436400 instead of 1351407600 -> Delta : -28800
- (25/03/2012 08:00 – France Time) FB Timestamp = 1332687600 instead of 1332655200 -> Delta : -32400
- (24/03/2012 23:30 – France Time) FB Timestamp = 1332657000 instead of 1332628200 -> Delta : -28800
- (27/10/2012 23:30 – France Time) FB Timestamp = 1351405800 instead of 1351373400 -> Delta : -32400
In fact I need a way to convert 31/10/2011 16H00 (PDT) to 31/10/2011 16H00 (Paris TZ)…
When you create the SimpleDateFormat you can specify the timezone. The Date it produced is GMT+0. You can display it in your local timezone by using another SimpleDateFormat with your timezone. (Or you could use JodaTime to do the same)
If you need the number of milli-seconds since 1/1/1970 in the PST timezone you can do
As GMT doesn’t have daylight savings changes it is a good general time to use.