Saturday, August 30, 2025
HomeLanguagesJavaOffsetDateTime of(LocalDate, LocalTime) method in Java with Examples

OffsetDateTime of(LocalDate, LocalTime) method in Java with Examples

The of(LocalDate date, LocalTime time, ZoneOffset offset) method of the OffsetDateTime class in Java is used to create an instance of OffsetDateTime from given instances of date, time and offset. This method creates an OffsetDateTime with the specified local date, local time and offset.

Syntax:

public static OffsetDateTime of(LocalDate date,
                                LocalTime time,
                                ZoneOffset offset)

Parameters: This method accepts three parameters:

  • date – It represents the local date.
  • time – It represents the local time.
  • offset – It represents the zone offset.

Return value: This method returns the OffsetDateTime.

Exception: This method does not throw any exception.

Below programs illustrate the of(LocalDate, LocalTime, ZoneOffset) method of OffsetDateTime class in Java:

Program 1:




// Java program to demonstrate
// OffsetDateTime
// of(LocalDate, LocalTime, ZoneOffset) method
  
import java.time.*;
import java.time.temporal.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // Create LocalDate object
        LocalDate date
            = LocalDate.parse(
                "2020-05-28");
  
        // Create LocalTime object
        LocalTime time
            = LocalTime.parse(
                "03:50:40");
  
        // Create OffsetDateTime object
        OffsetDateTime offsetdatetime
            = OffsetDateTime.of(
                date, time, ZoneOffset.UTC);
  
        // Print date-time
        System.out.println("DATE-TIME: "
                           + offsetdatetime);
    }
}


Output:

DATE-TIME: 2020-05-28T03:50:40Z

Program 2:




// Java program to demonstrate
// OffsetDateTime
// of(LocalDate, LocalTime, ZoneOffset) method
  
import java.time.*;
import java.time.temporal.*;
  
public class GFG {
    public static void main(String[] args)
    {
  
        // Create LocalDate object
        LocalDate date
            = LocalDate.of(
                2020, 5, 28);
  
        // Create LocalTime object
        LocalTime time
            = LocalTime.of(
                3, 50, 40);
  
        // Create OffsetDateTime object
        OffsetDateTime offsetdatetime
            = OffsetDateTime.of(
                date, time, ZoneOffset.UTC);
  
        // Print date-time
        System.out.println("DATE-TIME: "
                           + offsetdatetime);
    }
}


Output:

DATE-TIME: 2020-05-28T03:50:40Z

References:
https://docs.oracle.com/javase/10/docs/api/java/time/OffsetDateTime.html#of(java.time.LocalDate, java.time.LocalTime, java.time.ZoneOffset)

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32250 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6617 POSTS0 COMMENTS
Nicole Veronica
11792 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11840 POSTS0 COMMENTS
Shaida Kate Naidoo
6732 POSTS0 COMMENTS
Ted Musemwa
7014 POSTS0 COMMENTS
Thapelo Manthata
6689 POSTS0 COMMENTS
Umr Jansen
6704 POSTS0 COMMENTS