Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

how to format the date from GMT timezone to EST timezone?  RSS feed

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to format the date from GMT ( DB column's data type is time stamp) to EST timezone but i am not able to do it..
I tried lot of things but still i couldn't succeed.

some piece of code i am pasting--





Please help me.. Thanks in advance..
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What sort of format is AppConstants.Common.EST_DATE_FORMAT?

Why are you using EST to read the format if you want to convert it from GMT? Shouldn't you use a GMT type format there?
If you are reading a timestamp from a database, why do you need to convert it to a Date or Calendar object at all? Doesn't the database return a Timestamp object?
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... and welcome to the Ranch
 
arpit maurya
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:What sort of format is AppConstants.Common.EST_DATE_FORMAT?

Why are you using EST to read the format if you want to convert it from GMT? Shouldn't you use a GMT type format there?
If you are reading a timestamp from a database, why do you need to convert it to a Date or Calendar object at all? Doesn't the database return a Timestamp object?


AppConstants.Common.EST_DATE_FORMAT is nothing but the "yyyy-MM-dd HH:mm:ss a" format i am specifying in some CONSTANT file .
I don't know how to solve it so Can you please modify my code & send it..
Thank you so much..
 
arpit maurya
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:... and welcome to the Ranch



Thank you so much...
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you would have a String in this format?
2011-07-29 03:54:21 pm
 
arpit maurya
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:So you would have a String in this format?
2011-07-29 03:54:21 pm
yes..
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know any more. Sorry.

Anybody else?
 
Sheriff
Posts: 22844
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't convert a date from timezone A to timezone B, because a date doesn't have a timezone in the first place. So the question is meaningless.

You can certainly format a date to appear in timezone B, though. You already know how to do that: use a SimpleDateFormat, set its timezone to B, and use it to format the date. So just do that part.
 
arpit maurya
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:You can't convert a date from timezone A to timezone B, because a date doesn't have a timezone in the first place. So the question is meaningless.

You can certainly format a date to appear in timezone B, though. You already know how to do that: use a SimpleDateFormat, set its timezone to B, and use it to format the date. So just do that part.
yes It was my mistake actually, what i need is formatted date only.. after googling i found lots of answers but still i am not able to fix it..
Can you please let me know what could be the possible solution after seeing my code..
 
Paul Clapham
Sheriff
Posts: 22844
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure, I could give it a try. Post your code.
 
arpit maurya
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Sure, I could give it a try. Post your code.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!