Java Date Time Java Java API
java.time.OffsetTime
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.
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); }}
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); }}
16:13:47.130-05:0018:13:47.169-03:0022:13:47.169+01:0018: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); }}
16:13-05:0002:13+05:00