ven27 ven27 - 9 months ago 71
Android Question

Changing timezone to IST

I am programmatically trying to set the timezone to Indian Standard Time (IST) in Android, but nothing seems to work!

Here's the code snippet:

SimpleDateFormat s = new SimpleDateFormat("HH:mm:ss");
// TimeZone.setDefault(TimeZone.getTimeZone("GMT +5:30"));
// TimeZOne.setDefault(TimeZone.getTimeZone("IST"));
Calendar c = Calendar.getInstance();

Answer Source

Rather than changing the default time zone (which you're doing after creating the SimpleDateFormat) you should just set the time zone of the SimpleDateFormat:

SimpleDateFormat s = new SimpleDateFormat("HH:mm:ss");
System.out.println(s.format(new Date()));