Java Tutorials


Java 8 Date Time Classes

OffsetDateTime class Usage

   OffsetDateTime represents ,

Creating a OffsetDateTime Object. OffsetDateTime's

now()

method returns system's date.

of

method returns specific date of your choice. Both are static methods.
Creating a OffsetDateTime Object

Creating offsetDateTime Object using LocalDateTime object's atOffset method

In this case you should know the offset value of perticular city

      		Creating a America/New_York time using offset value -5:00
      		
		LocalDateTime ldt = LocalDateTime.now();
		OffsetDateTime odt = ldt.atOffset(ZoneOffset.ofHours(-5))
      		System.out.println(odt);
      		2023-01-25T21:57:14.750721-05:00
      

ADS