Close

Java Date Time - OffsetTime.of() Examples

Java Date Time Java Java API 


Class:

java.time.OffsetTime

java.lang.Objectjava.lang.Objectjava.time.OffsetTimejava.time.OffsetTimejava.time.temporal.TemporalTemporaljava.time.temporal.TemporalAdjusterTemporalAdjusterjava.lang.ComparableComparablejava.io.SerializableSerializableLogicBig

Methods:

public static OffsetTime of(LocalTime time,
                            ZoneOffset offset)

Returns the new OffsetTime instance, created from the provided LocalTime and ZoneOffset values.


public static OffsetTime of(int hour,
                            int minute,
                            int second,
                            int nanoOfSecond,
                            ZoneOffset offset)

Returns the new OffsetTime instance, created from the specified hours, minutes, seconds, nano-seconds and ZoneOffset values.


Examples


package com.logicbig.example.offsettime;

import java.time.LocalTime;
import java.time.OffsetTime;
import java.time.ZoneOffset;

public class OfExample {

public static void main(String... args) {

OffsetTime t = OffsetTime.of(LocalTime.MIDNIGHT, ZoneOffset.ofHours(-6));
System.out.println(t);

t = OffsetTime.of(LocalTime.MIDNIGHT, ZoneOffset.UTC);
System.out.println(t);
}
}

Output

00:00-06:00
00:00Z




package com.logicbig.example.offsettime;

import java.time.OffsetTime;
import java.time.ZoneOffset;

public class OfExample2 {

public static void main(String... args) {
OffsetTime t = OffsetTime.of(12, 35, 23, 20000,
ZoneOffset.of("-10:30"));
System.out.println(t);

t = OffsetTime.of(12, 35, 23, 20000,
ZoneOffset.ofHours(-6));
System.out.println(t);
}
}

Output

12:35:23.000020-10:30
12:35:23.000020-06:00




See Also