Guest User

Untitled

a guest
Jun 19th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. My Calender and TimeZone logic.
  2.  
  3. I have a time zone: TimeZone tz; //The timezone
  4. and I have a calender : Calendar cal;
  5. I also have a date : Date currentTimeD;
  6.  
  7.  
  8. //My default constructor uses only timezone as thus:
  9.  
  10. tz = TimeZone.getTimeZone("America/Los_Angeles");
  11.  
  12. //That should set the time zone to Pacific Standard Time. When I print out the timezone I get
  13. "Pacific Standard Time". So the timezone is being set.
  14.  
  15. //Now I need to get the time:
  16.  
  17. cal = Calendar.getInstance();
  18.  
  19. //'m getting the default time and date from the systems locality. In this case, California.
  20.  
  21. cal.setTimeZone(tz);
  22.  
  23. //I'm setting the timezone to tz, which is PST.
  24.  
  25. timeZoneOffset=tz.getRawOffset();
  26.  
  27. //I'm setting the offset in milliseconds into timeZoneoffset. It is -28800000
  28.  
  29. currentTimeD=cal.getTime();
  30.  
  31. //Here I'm getting my time and putting into my date class.
  32.  
  33. //And below I'm setting my int variables hour, minute, and second to the variables in currentTimeD.
  34. hour=currentTimeD.getHours();
  35. minute=currentTimeD.getMinutes();
  36. second=currentTimeD.getSeconds();
  37.  
  38.  
  39. //All seems well. Yet when I change
  40. tz = TimeZone.getTimeZone("America/Los_Angeles");
  41.  
  42. //to
  43. tz = TimeZone.getTimeZone("America/Chicago");
  44.  
  45. //I get the same time, but I output "Central Standard Time".
Add Comment
Please, Sign In to add comment