Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calendar class

 
Frank Rennie
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm confused about what the TimeZone arg in the Calendar class actually does. In the code segment below...



...I'd expect the last line to output the current time in Los Angeles. Instead, it prints the time in my own time zone. Have I misunderstood what TimeZone is supposed to do, or is there a mistake in my code?

If I call System.out.println(cal.getTimeZone());, it shows that the Calendar object has the LA time zone, so why doesn't it print the time there?
 
Sidharth Khattri
Ranch Hand
Posts: 125
Java Linux Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frank Rennie wrote:I'm confused about what the TimeZone arg in the Calendar class actually does. In the code segment below...



...I'd expect the last line to output the current time in Los Angeles. Instead, it prints the time in my own time zone. Have I misunderstood what TimeZone is supposed to do, or is there a mistake in my code?

If I call System.out.println(cal.getTimeZone());, it shows that the Calendar object has the LA time zone, so why doesn't it print the time there?


Are you studying for scjp 6? I've no idea TimeZone class is also on the objective, it's not mentioned anywhere in K and B book.
 
Frank Rennie
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm studying for the OCPJP7 and have come across a couple of questions on the Calendar class in the Enthuware tests.

Even if it's not in the official exam, I'd still like to know how it's supposed to work.
 
Sidharth Khattri
Ranch Hand
Posts: 125
Java Linux Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frank Rennie wrote:I'm studying for the OCPJP7 and have come across a couple of questions on the Calendar class in the Enthuware tests.

Even if it's not in the official exam, I'd still like to know how it's supposed to work.


Oh, I got worried I missed something.
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frank Rennie wrote:...I'd expect the last line to output the current time in Los Angeles. Instead, it prints the time in my own time zone.


It prints here -



Seems fine to me.

Regards,
Dan

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic