Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- My Calender and TimeZone logic.
- I have a time zone: TimeZone tz; //The timezone
- and I have a calender : Calendar cal;
- I also have a date : Date currentTimeD;
- //My default constructor uses only timezone as thus:
- tz = TimeZone.getTimeZone("America/Los_Angeles");
- //That should set the time zone to Pacific Standard Time. When I print out the timezone I get
- "Pacific Standard Time". So the timezone is being set.
- //Now I need to get the time:
- cal = Calendar.getInstance();
- //'m getting the default time and date from the systems locality. In this case, California.
- cal.setTimeZone(tz);
- //I'm setting the timezone to tz, which is PST.
- timeZoneOffset=tz.getRawOffset();
- //I'm setting the offset in milliseconds into timeZoneoffset. It is -28800000
- currentTimeD=cal.getTime();
- //Here I'm getting my time and putting into my date class.
- //And below I'm setting my int variables hour, minute, and second to the variables in currentTimeD.
- hour=currentTimeD.getHours();
- minute=currentTimeD.getMinutes();
- second=currentTimeD.getSeconds();
- //All seems well. Yet when I change
- tz = TimeZone.getTimeZone("America/Los_Angeles");
- //to
- tz = TimeZone.getTimeZone("America/Chicago");
- //I get the same time, but I output "Central Standard Time".
Add Comment
Please, Sign In to add comment