Java Get Current Date for a Specific Time Zone


In order to get the Date in Java for a specific TimeZone, you can make use of the LocalDate class from the Date-Time API and pass in the ZoneId for the timezone in the static now method.


Example:
import java.time.LocalDate;
import java.time.ZoneId;

public class GetDateTimeZoned {

    public static void main(String[] args) {
        
        LocalDate dateInChicago = LocalDate.now(ZoneId.of("America/Chicago"));
        LocalDate dateInMumbai = LocalDate.now(ZoneId.of("Asia/Kolkata"));
        LocalDate dateInTokyo = LocalDate.now(ZoneId.of("Asia/Tokyo"));
        LocalDate dateInLondon = LocalDate.now(ZoneId.of("Europe/London"));


        System.out.println("Date in Chicago " + dateInChicago);
        System.out.println("Date in Mumbai: " + dateInMumbai);
        System.out.println("Date in Tokyo: " + dateInTokyo);
        System.out.println("Date in London: " + dateInLondon);

    }
}

Output:

Date based on Time Zone Example Java

Make sure to pass in the correct timezone String or else you will get ZoneRulesException: Unknown time-zone exception.

You can find the complete list of TimeZone on this reference page: Time Zone and Off-Set List

-




Have Questions? Post them here!