I need to get hours value of Calendar time in another timezone. I tried this example: https://stackoverflow.com/a/7695910/775523 (java.util.Calendar section) but it prints 15 for the last cal.get(Calendar.HOUR_OF_DAY) (I expect to have 17!). So what is a correct way to get number of hours in another timezone - I use build 1.7.0_21-b11. Thanks.
Asked
Active
Viewed 79 times
1 Answers
0
you can use this code reference
Date date = new Date();
DateFormat formatter = new SimpleDateFormat("dd MMM yyyy HH:mm:ss z");
formatter.setTimeZone(TimeZone.getTimeZone("Asia/Tokyo"));
// Prints the date in the CET timezone
System.out.println(formatter.format(date));
// Set the formatter to use a different timezone
formatter.setTimeZone(TimeZone.getTimeZone("Australia/Melbourne"));
// Prints the date in the IST timezone
System.out.println(formatter.format(date));
you can use date.getHours();

Bhargav Modi
- 2,605
- 3
- 29
- 49