• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with Calendar().getTime()  RSS feed

 
Tom Rader
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My calender date is set to US/Pacific Timezone but when I print

dateCalender.getTime()

it prints the exactly same date/time but timezone IST (i am from India). For Example it prints

Calender TimeZone: Pacific Standard Time
Calender : Wed Oct 09 00:00:00 IST 2013



I dont understand this behavior of Calender getTime. Please help.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tom Rader wrote: I dont understand this behavior of Calender getTime. Please help.

You might find ABriefHistoryOfJavaTime worth reading, because hopefully it will explain it for you.

But simply put: Java times are ALWAYS the same. If you want to get it to display correctly, change the TimeZone for your Calendar.

Winston
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tom Rader wrote:My calender date is set to US/Pacific Timezone but when I print
dateCalender.getTime()
it prints the exactly same date/time but timezone IST (i am from India). For Example it prints
Calender TimeZone: Pacific Standard Time
Calender : Wed Oct 09 00:00:00 IST 2013
I dont understand this behavior of Calender getTime. Please help.

Perhaps I should ask: What are you using to display the time? Because the Calendar class does NOT contain methods for display. Also: is the actual time correct?
Wed Oct 09 00:00:00 IST 2013
is probably something like:
Tue Oct 08 11:30:00 PST 2013
since most of India is either 11.5 or 12.5 hours ahead of PST (not sure about DST in India).

Winston

PS: And BTW, it's PDT at the moment.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!