Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Problem with Date Format - UTC

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I am having one problem while converting date format.
I am getting date as "2010-01-27 06:43:34" string in XML. I need to store it into UTC format.
but I am not able to do it.
Below is code:


it is returning "Wed Jan 27 12:13:34 IST 2010" output and I want it into UTC.

Thanks in advance.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the variable timeZone in your code? Is it set to UTC or to some other timezone?

Is the string you are parsing a timestamp in UTC? Then you need to set the timezone on the SimpleDateFormat object too (to the UTC timezone, ofcourse).
 
Patel Chintan
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jesper Young wrote:What is the variable timeZone in your code? Is it set to UTC or to some other timezone?

Is the string you are parsing a timestamp in UTC? Then you need to set the timezone on the SimpleDateFormat object too (to the UTC timezone, ofcourse).



timezone is UTC.
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Patel Chintan wrote:Hi I am having one problem while converting date format.
I am getting date as "2010-01-27 06:43:34" string in XML. I need to store it into UTC format.



Forgive my slightly off topic answer, but I ran into date strings lacking a time zone indicator recently one too often: if possibly at all, make sure to get a time zone indicator into the XML. Otherwise it has at least 24 different interpretations, depending on which time zone it actually is. You may currently know from context, but tomorrow someone changes his/her mind and switches from UTC to localtime or vice versa.
 
These are not the droids you are looking for. Perhaps I can interest you in a tiny ad?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic