Java Instant atZone() method

The atZone() method of Java Instant class is used to combine the instant with a time-zone to create a ZonedDateTime.

Syntax

Parameters

Zone - The Zone to combine with, not null.

Return

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

Exceptions

DateTimeException - If the result exceeds the supported range.

Example 1

Output:

The output will be like this.

2018-07-17T10:37:30Z
2017-07-17T13:37:30+03:00[Asia/Aden]

Example 2

Output:

Machine Time Now :   2016-11-29T14:23:25.551Z
In New Delhi(Asia) Time Zone :   2018-07-17T06:23:25.551-08:00[Asia/New_Delhi]
In 'GMT+01:00' Time Zone :   2016-07-17T15:23:25.551+01:00[GMT+01:00]