Close

Java Date Time - OffsetTime.now() 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 now()

Returns the current OffsetTime from the system clock in the default time-zone.


public static OffsetTime now(ZoneId zone)

Returns the current OffsetTime from the system clock and in the provided ZoneId.


public static OffsetTime now(Clock clock)

Returns the current date-time from provided clock.


Examples


package com.logicbig.example.offsettime;

import java.time.OffsetTime;

public class NowExample {

public static void main(String... args) {
OffsetTime d = OffsetTime.now();
System.out.println(d);
}
}

Output

16:13:45.033-05:00




package com.logicbig.example.offsettime;

import java.time.OffsetTime;
import java.time.ZoneId;

public class NowExample2 {

public static void main(String... args) {
OffsetTime d = OffsetTime.now(ZoneId.systemDefault());
System.out.println(d);

d = OffsetTime.now(ZoneId.of("-3"));
System.out.println(d);

d = OffsetTime.now(ZoneId.of("GMT+01:00"));
System.out.println(d);

d = OffsetTime.now(
ZoneId.of("America/Argentina/Buenos_Aires"));
System.out.println(d);
}
}

Output

16:13:47.130-05:00
18:13:47.169-03:00
22:13:47.169+01:00
18:13:47.169-03:00




package com.logicbig.example.offsettime;

import java.time.Clock;
import java.time.OffsetTime;
import java.time.ZoneId;

public class NowExample3 {

public static void main(String... args) {
OffsetTime d = OffsetTime.now(Clock.tickMinutes(
ZoneId.systemDefault()));
System.out.println(d);

OffsetTime d2 = OffsetTime.now(Clock.tickMinutes(
ZoneId.of("Indian/Maldives")));
System.out.println(d2);
}
}

Output

16:13-05:00
02:13+05:00




See Also