In this article, we will be covering how to convert a given time into different timezones in Java. We will be using the ZoneId, Instant, ZonedDateTime classes for this, which are classes available in the java.time package and are more reliable than the java.util date time classes.
In this example, we will not be using the Date class of java and will rather use the new Instant class to get the current time. We can get the current time using the Instant class,
Instant now = Instant.now();
Convert Time to specific Timezone
For this, we will be creating an instance of the Instant class which will have the current time in GST timezone and we will then use the ZonedDateTime class and convert the time into any specific timezone, in this case, let's convert it into the "Asia/Kolkata" timezone. Below we have the program for it.
This is a super simple way of doing it and we would recommend you to stop using the java.util.Date class and start using the java.time package classes for your future program/applications.