Java Data Type How to - Create date time in system default timezone








Question

We would like to know how to create date time in system default timezone.

Answer

import java.time.ZoneId;
import java.time.ZonedDateTime;
/*from  w  w w .j  a  v a  2s  .c  om*/
public class Main {

  public static void main(String[] args) {
    ZonedDateTime myZonedDateTime = ZonedDateTime.of(2014, 1, 31, 11, 20, 30, 93020122, ZoneId.systemDefault());
    System.out.println(myZonedDateTime);
  }
}

The code above generates the following result.