Using Java 8
Java 8 introduced a new Date-Time API for working with dates and times which was largely based on the Joda-Time library.
The Instant class from Java Date Time API models a single instantaneous point on the timeline in UTC. This represents the count of nanoseconds since the epoch of the first moment of 1970 UTC.
First, we'll obtain the current Instant from the system clock and ZoneId for a time zone name:
Instant nowUtc = Instant.now();
ZoneId asiaSingapore = ZoneId.of("Asia/Singapore");
Finally, the ZoneId and Instant can be utilized to create a date-time object with time-zone details. The ZonedDateTime class represents a date-time with a time-zone in the ISO-8601 calendar system:
ZonedDateTime nowAsiaSingapore = ZonedDateTime.ofInstant(nowUtc, asiaSingapore);
We've used Java 8's ZonedDateTime to represent a date-time with a time zone.
In order to learn more about Java, you should go for our top Java course online.