0

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.

Community
  • 1
  • 1
dbf
  • 6,399
  • 2
  • 38
  • 65
  • possible duplicate of [How to change TIMEZONE for a java.util.Calendar/Date](http://stackoverflow.com/questions/13470830/how-to-change-timezone-for-a-java-util-calendar-date) – Jens Mar 17 '15 at 10:12

1 Answers1

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