Get local time and date in Java based on timezone

Java 8 introduces ZonedDateTime, you can now easily get the local time and date based on timezones. Take look at the example below

	Instant now = Instant.now();
	ZoneId zoneId = ZoneId.of("America/Los_Angeles");
	ZonedDateTime dateAndTimeInLA = ZonedDateTime.ofInstant(now, zoneId);
	System.out.println(dateAndTimeInLA);

Leave a Reply

Your email address will not be published. Required fields are marked *