• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with Date Format - UTC  RSS feed

 
Patel Chintan
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.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • 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.
 
Harald Kirsch
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!