my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Calendar class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Calendar class" Watch "Calendar class" New topic
Author

Calendar class

Frank Rennie
Greenhorn

Joined: Sep 18, 2013
Posts: 10
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

Joined: Sep 16, 2013
Posts: 121

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.


OCPJP 6 - 96%
Frank Rennie
Greenhorn

Joined: Sep 18, 2013
Posts: 10
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

Joined: Sep 16, 2013
Posts: 121

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

Joined: Jul 09, 2001
Posts: 1176
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


William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Calendar class