-2

I am trying to get current time of a particular timeZone but when I write this:

Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("America/Boise"));
System.out.println(calendar.getTime());

it always prints UTC time followed by "UTC" word maybe because on the server timeZone is set to UTC but still it shouldn't happen as I explicitly specified the timezone here.

Vivek Sadh
  • 4,230
  • 3
  • 32
  • 49
  • 2
    A Calendar instance is stored in UTC. You have to use a SimpleDateFormat and specify the time zone to get the date and time for a particular timezone. – Gilbert Le Blanc Nov 14 '16 at 12:11
  • yes ""America/Boise"" is supported TimeZone ID. you can check this by calling java.util.TimeZone.getAvailableIDs(). – aviad Nov 14 '16 at 12:17
  • With Java 8: `ZonedDateTime.now(ZoneId.of("America/Boise"))`... – assylias Nov 14 '16 at 12:47

1 Answers1

0

It returns UTC because the method TimeZone.getTimeZone(String id) returns the specified TimeZone, or the GMT zone if the given ID cannot be understood. In your case, since the given ID cannot b understood, it returns the GMT Zone.

Andrei Olar
  • 2,270
  • 1
  • 15
  • 34
  • 2
    "America/Boise" is a supported Timezone ID as can be verified by java.util.TimeZone.getAvailableIDs(). – aviad Nov 14 '16 at 12:17