Wednesday 11 March 2020

Set Default time zone to the application

'TimeZone.setDefault' method is used to set time zone.

Example
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));

App.java
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
Previous                                                    Next                                                    Home

No comments:

Post a Comment