• 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 offset to Timezone ID conversion

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

I was searching for one function that convert the timezone offset value in milliseconds to the corresponding TimeZone String ID representation.

One more doubt is that, my client is sending me time in milliseconds, if I creat a Date object with this time will it represent the clients TimeZone or will it be the TimeZone of my machine where the Date object is created.

Also, My Time Zone is "IST". It is 5:30 hrs ahead of UTC. But when I created one Date object and called getTimeZoneOffset() function on that what i am getting is -330. I am not able to understand why it is coming as negative even when the time is ahead of UTC.

I would greatly appreciate if somebody can help me out.

Thanks in advance,
Martin
 
Marshal
Posts: 28235
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

Originally posted by Roshni Paul:
One more doubt is that, my client is sending me time in milliseconds, if I creat a Date object with this time will it represent the clients TimeZone or will it be the TimeZone of my machine where the Date object is created.

No. Neither. A Date object does not represent any time zone. It is an absolute number, the number of milliseconds since midnight GMT on January 1, 1970. You can format it for any time zone; for example the same Date object represents 2006 March 24 11:00:00 UTC and 2006 March 24 16:30:00 IST.

Also, My Time Zone is "IST". It is 5:30 hrs ahead of UTC. But when I created one Date object and called getTimeZoneOffset() function on that what i am getting is -330. I am not able to understand why it is coming as negative even when the time is ahead of UTC.

Sorry, I don't see a method of that name in any class in the standard Java API. If I create a TimeZone for "IST" and then call its getOffset(long) method, it returns 19800000 -- a positive number which is the number of milliseconds in 5.5 hours. You'll have to ask the writer of that method about it.
 
Roshni Paul
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,

Thankyou very much for your reply. I very much agree with you that Date is an absolute number, the number of milliseconds since midnight GMT on January 1, 1970. But if it does not contain timezone information how can be the same absolute value be presented as different times values for different time zones. Could you please put little more light on how this actually works.

Could you please suggest some function that mapps the offset to the time zone string id?

Also,

Date d=new Date();
long m=d.getTimezoneOffset();
System.out.println(m);

This is the getTimezoneOffset() function that I mentioned. It is from java API itself. The out put I am getting is -330.

Thanks,
Rosh
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should look at the Calendar class, it looks like it has everything you are looking for. Dates getTimezoneOffset() has been deprecated since JDK 1.1.
 
Paul Clapham
Marshal
Posts: 28235
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
Notice that the Date object is not doing this presentation. It just contains a number.

Could you please suggest some function that mapps the offset to the time zone string id?

You want to know what timezone is UTC - 6 hours for example? There is no such function because it is possible there are several timezones with that offset. But TimeZone.getAvailableIDs(offset) will return you an array of them. (And its API documentation explains why it must return an array.)
[ March 27, 2006: Message edited by: Paul Clapham ]
 
Roshni Paul
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Paul,

Thank you very much. getAvailableIDs(offset) was exactly the function that was searching for.

Thanks,
Rosh
 
reply
    Bookmark Topic Watch Topic
  • New Topic