• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

TimeZone Conversion

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

I was messing around with the Facebook API. Basiclly i created a calendar event on facebook starting at 19 Nov, 14:15 and end 15:15, then used the api to get the event as XML.

Now the event start date appeared as:

<start_time>1227042900</start_time>
<end_time>1227046500</end_time>

The 10-digit number represents the number of seconds since 1970 accurate down to the second, and is the most common way to express timestamp values, The java Date constructor as far as i know takes a 13-digit number accurate down to the millisecond to work correctly and create a Date. So i multipled the xml timestamp number by 1000 to make it accurate down to millisecond and created the start date in java using the following code.


Which later displayed as 19 Nov 22:15 which was a discremency of 8 hours.

According to the facebook forum they think Since there's no timezone specified when you enter an event, it seems facebook stores it internally as US Pacific Standard Time (which is GMT-8). When it is exported as a timestamp, it gets "normalized" to standard timestamp conventions by expressing it as GMT. In other words when i enter 14:15, facebook will treat this as 14:15 USPST, which equals 22:15 GMT when converted above.

So i wonder can any body show me how to read the above xml timestamp result into java so it can be converted into the timezone of the user who created it. Facebook also stores the timezone of the user who queried the facebook server. My time zone appears as 0, So i wonder how can i in java give the facebook server time zone and event time start time, compare them to my time zone, get the discrmency and deduct as neccessary? Any help appreciated.

best
Mark Hughes

[ November 19, 2008: Message edited by: Mark Hughes ]
[ November 19, 2008: Message edited by: Mark Hughes ]
 
author
Posts: 3285
13
Mac OS X Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

A little bit of a tough one alright! Unfortunately in terms of creating a Date in Java you can only seed it with the 13 digit number that is time since 1970 in GMT.

You can however then create a Calendar object out of that and then set the timezone/locale (that you get separately from Facebook) on that Calendar object. See the Calendar and Gregorian calendar API.
 
Mark Hughes
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Martijn ,

Thanks for your reply, yes i looked into what you suggested, now im thinking that even if i was just to create the formatted time to appear as the PST GMT-8 time than that would appear as the time entered when the event was created and would be correct. So i tried this code, basically create calendar object with GMT-8 timezone and hope that when i pass in the facebook time stamp it appears as the original time i enter when creating the event.



Now the event i created is as follows;
Date:19 November 2008
Time:16:00 - 17:00

But the above code result is "Correct Time:2008-11-20 01:00" which is really off, any thoughts??

Best
Mark
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Depends where you are. If you are in Western North America, then by the time 4pm 19th November comes, it will be after midnight here (UK), so 1am 20th November looks right. You might need to put some sort of timezone correction in.
 
Mark Hughes
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Campbell ,

Yup im based in Ireland, and i create the event intending to have it in Ireland, so id like to pull the event out and display it as the time i entered and not 01:00 in the morning. I finding it a bit tricky to say the least lol

Best
Mark
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You might find it helpful to set the time zone on your SimpleDateFormat as well. I'm not sure that will work but that's just because I didn't spend the time following all of the conversions there.

By the way "Etc/GMT-8" is almost certainly not the right timezone to use. It may work OK now but come March of next year you may find it to be an hour off. Try "America/Los_Angeles" instead.
 
Mark Hughes
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Guys,

Yup thanks Paul i tried what you suggested and changed the time zone to America/LA and also set the time on the SimpleDateFormat as follows:



And then i got the time as expected, i think doing it like this will always give the correct Times back as you pull them out in the same format as they were entered.

Thansk to everyone for all the help and feed back

Best
Mark
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure how much I actually helped, but well done

And it is useful to leave the solution there in case anybody needs to search for it in future.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic