• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

How to extract zone from a date which has it.

 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a date in this format ->SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm Z");

How can i extract just Z ie. Zone from it, is it possible with stringifying and extracting it.
 
Bartender
Posts: 1166
17
Netbeans IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't really understand your requirement. java.util.Date objects do not have an explicit time zone (the implicit one is UTC) so it seems you must be considering the date as a String. If one uses class SimpleDateFormat to parse this to a java.util.Date then one loses any time zone information that was explicit in the String so I suspect one has to parse the String oneself to extract the time zone. I would use a regular expression but they are not to everyone's taste.

Once you have the time zone extracted as a String then one can convert it to a TimeZone object using one of the static methods of class TimeZone.
 
They weren't very bright, but they were very, very big. Ad contrast:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic