ven27 ven27 - 1 year ago 123
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()));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download