Java Instant atOffset() method

The atOffset() method of Java Instant class is used to combine the instant with an offset to create an OffsetDateTime.

Syntax

Parameters

offset - The offset to combine with, not null.

Return

The offset date-time formed from this instant and the specified offset, not null.

Exceptions

DateTimeException - If the result exceeds the supported range.

Example 1

Output:

The output will be like this.
2017-02-03T10:37:30Z
2017-02-03T15:37:30+05:00

Example 2

Output:

2017-07-03T22:35:29.771+05:30 
2017-07-03T22:35:29.771
2017-07-03
22:35:29.771
2017-07-03T22:35:29.771+05:30
2017-07-03T17:05:29.771Z
22:35:29.771+05:30

Example 3

Output:

 Year : 2017
 Month : 7 
 Day of Month : 6
 Day of Week : THURSDAY 
 Day of Year : 187
 Offset : +05:30

Example 4

Output:

Hour : 21
Minute : 41
Second : 10
Nano : 941000000