Java OffsetDateTime class

Description

Java OffsetDateTime class

import java.time.OffsetDateTime;
import java.time.ZoneOffset;

public class Main {
  public static void main(String[] args) {
    // Get the current offset date time
    OffsetDateTime odt1 = OffsetDateTime.now();
    System.out.println("Current offset datetime: " + odt1);

    // Create a zone offset +05:30
    ZoneOffset offset = ZoneOffset.ofHoursMinutes(5, 30);
    // Create an offset date time
    OffsetDateTime odt2 = OffsetDateTime.of(2020, 5, 11, 18, 10, 30, 0, 
        offset);//from w ww.j a  v  a  2  s.c o  m
    System.out.println("An offset datetime: " + odt2);


  }
}



PreviousNext

Related