Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Any API that returns the timezone in GMT(+/-) format?

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

I went through the Timezone package but could not find the exact API that returns the timezone in GMT, rather it returns as "Europe/Berlin".

As far as I had read through the API doc, I found that the Timezone APIs like getTimezone(), getDefault() methods return only the ID in this format "Europe/Berlin" and not in GMT format.

I cannot use either the getTimeZone("....") or the custom ID creation method, as I want API to return the default timezone id in GMT format and not create any timezone parameters.

Please let me know if any such API exists or is there any other way of obtaining the above.

Thanks in advance!!!
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you mean with "GMT format"? Do you mean a string like "+0200", which represents the offset in hours and minutes from GMT/UTC?

Class TimeZone has methods like getOffset() and getRawOffset() which return the offset of the timezone from UTC as an integer (a number of milliseconds). This number can easily be formatted to a string like "+0200". For example:
 
ram shyam
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

Many thanks for your reply.
Yes, this is what I want. But could you please explain the parameter "%s%02d%02d" used in format method?

Thanks in advance!!
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by ram shyam:
hi,

Many thanks for your reply.
Yes, this is what I want. But could you please explain the parameter "%s%02d%02d" used in format method?

Thanks in advance!!



Have a look at the format() method in String javadoc. Note that this method was added in JRE1.5, so if you're using an earlier version you can't use this method.
 
ram shyam
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Many thanks for your reply!!!
 
reply
    Bookmark Topic Watch Topic
  • New Topic