Java 8 – How to convert LocalDateTime to an OffsetDateTime ?

In this article, we will learn how to convert LocalDateTime to an OffsetDateTime using atOffset(ZoneOffset) method of LocalDateTime provided in Java 1.8 version

For OffsetDateTime to LocalDateTime conversion, read Java 8 – How to convert OffsetDateTime to LocalDateTime ?

Convert LocalDateTime to an OffsetDateTime :

  • LocalDateTime has a method atOffset() which takes ZoneOffset as an argument and returns OffsetDateTime
    • atOffset() – Returns a Offset date-time from invoking LocalDateTime with a zone-offset
  • Using this method, it is very easy to convert LocalDateTime to OffsetDateTime by adding zone-offset information
  • After conversion, OffsetDateTime have Date & Time parts are same as that of LocalDateTime
  • Lets see an example for conversion of LocalDateTime to OffsetDateTime in the below illustration

package in.bench.resources.java8.localdatetime.examples;

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

public class ConvertLocalDateTimeToOffsetDateTime {

	public static void main(String[] args) {

		// 1. get current System Date/time
		LocalDateTime localDateTime =;
		System.out.println("Current System Date/time is :- \n" + localDateTime);

		// 2. get system default zone offset
		ZoneOffset zoneOffset = ZoneOffset.of("+05:30");
		System.out.println("\nZone Offset is :- \n" + zoneOffset);

		// 3. convert LocalDateTime to OffsetDateTime using atOffset(zoneOffset)
		OffsetDateTime offsetDateTime = localDateTime.atOffset(zoneOffset);
		System.out.print("\nConversion of LocalDateTime to OffsetDateTime is :- \n"
				+ offsetDateTime);


Current System Date/time is :- 

Zone Offset is :- 

Conversion of LocalDateTime to OffsetDateTime is :- 

Related Articles:


Happy Coding !!
Happy Learning !!

Java 8 – How to convert LocalDateTime to an Instant ?
Java 8 – How to convert LocalDateTime to ZonedDateTime ?