'TimeZone.setDefault' method is used to set time zone.
Example
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
package com.sample.app;
import java.util.Date;
import java.util.TimeZone;
public class App {
public static void main(String[] args) {
Date beforeSettingTimeZone = new Date();
System.out.println("beforeSettingTimeZone : " + beforeSettingTimeZone);
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
Date afterSettingTimeZone = new Date();
System.out.println("afterSettingTimeZone : " + afterSettingTimeZone);
}
}
Output
beforeSettingTimeZone : Sun Dec 29 13:37:18 IST 2019
afterSettingTimeZone : Sun Dec 29 08:07:18 UTC 2019
You may
like
No comments:
Post a Comment