Close

Java Date Time - ZonedDateTime.of() Examples

Java Date Time Java Java API 


Class:

java.time.ZonedDateTime

java.lang.Objectjava.lang.Objectjava.time.ZonedDateTimejava.time.ZonedDateTimejava.time.temporal.TemporalTemporaljava.time.chrono.ChronoZonedDateTimeChronoZonedDateTimejava.io.SerializableSerializableLogicBig

Methods:

public static ZonedDateTime of(LocalDate date,
                               LocalTime time,
                               ZoneId zone)

Returns an instance of ZonedDateTime from a local date and time.


public static ZonedDateTime of(LocalDateTime localDateTime,
                               ZoneId zone)

Returns an instance of ZonedDateTime from a local date-time and zone ID.


public static ZonedDateTime of(int year,
                               int month,
                               int dayOfMonth,
                               int hour,
                               int minute,
                               int second,
                               int nanoOfSecond,
                               ZoneId zone)

Returns an instance of ZonedDateTime from a year, month, day, hour, minute, second, nanosecond and time-zone.

Examples


package com.logicbig.example.zoneddatetime;

import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;

public class OfExample {

public static void main(String... args) {
ZonedDateTime d = ZonedDateTime.of(LocalDate.now(),
LocalTime.NOON, ZoneId.of("Australia/Perth"));
System.out.println(d);

}
}

Output

2017-05-01T12:00+08:00[Australia/Perth]




package com.logicbig.example.zoneddatetime;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;

public class OfExample2 {

public static void main(String... args) {
ZonedDateTime d = ZonedDateTime.of(LocalDateTime.now(),
ZoneId.of("Canada/Central"));
System.out.println(d);
}
}

Output

2017-05-01T16:01:30.844-05:00[Canada/Central]




package com.logicbig.example.zoneddatetime;

import java.time.ZoneId;
import java.time.ZonedDateTime;

public class OfExample3 {

public static void main(String... args) {
ZonedDateTime d = ZonedDateTime.of(2016, 10, 13, 22, 54, 25, 10000,
ZoneId.of("Europe/Paris"));
System.out.println(d);

}
}

Output

2016-10-13T22:54:25.000010+02:00[Europe/Paris]




See Also