I'm trying to convert the hour 8:00am EST (America/New_York), to display in whatever time that would be on the users system default zone. The date is not needed, only the time. I have been searching and I can only find ways to convert the current time.
-
2A quick google search starts with [Convert date and time between timezone](https://mkyong.com/java/java-convert-date-and-time-between-timezone/). Display is then handled by a `DateTimeFormatter`, but since you can have timezones which are beyond +/- 12 hours, the date is kind of important – MadProgrammer Sep 23 '21 at 02:53
-
1Hi, please learn that you’re expected to search before posting a question here. In many cases that will give you a better answer faster than anyone can type just a short answer here. If your search is not enough, tell us what you found and how it fell short of solving your problem. Showing an effort on your part will make a lot of users prepared to do a greater effort on theirs. And they will know much more exactly what it is you need to know, providing for answers that are a lot more helpful to you. – Ole V.V. Sep 24 '21 at 09:35
-
America/New_York is on summer time (DST, EDT) for the greater part of the year. The conversion must be different depending on whether it is on that day, and also depending on whether the user’s default time zone is. So can we know the date? If not, you cannot perform the conversion. – Ole V.V. Sep 24 '21 at 09:37
2 Answers
You need to use ZonedDateTime
and display only time part using DateTimeFormatter
. Something like this:
//assuming the server is in US
ZoneId serverZone = ZoneId.of("US/Eastern");
ZoneId userZone = ZoneId.of("Asia/Tokyo");
ZonedDateTime nyTime = ZonedDateTime.now(serverZone);
ZonedDateTime userTime = nyTime.withZoneSameInstant(userZone);
String pattern = "hh:mm a z VV";
DateTimeFormatter dtf = DateTimeFormatter.ofPattern(pattern);
System.out.println("Server time: " + dtf.format(nyTime));
System.out.println("User time: " + dtf.format(userTime));
Output:
Server time: 08:29 AM EDT US/Eastern
User time: 09:29 PM JST Asia/Tokyo

- 16,980
- 2
- 14
- 44
-
1This does not give you the current time: `ZonedDateTime.of(LocalDateTime.now(), serverZone)`. Use `ZoneDateTime.now(serverZone)`. – Ole V.V. Sep 24 '21 at 10:02
For the sake of the example I am assuming that you want to convert today at 8 AM EDT to the user’s default time zone. Without a date we cannot perform the conversion correctly. Like onkar ruikar in the other answer I am using and recommending java.time, the modern Java date and time API, for all of your time work.
ZoneId sourceZone = ZoneId.of("America/New_York");
ZoneId targetZone = ZoneId.systemDefault();
LocalTime sourceTime = LocalTime.of(8, 0);
ZonedDateTime sourceDateTime = ZonedDateTime.now(sourceZone).with(sourceTime);
ZonedDateTime targetDateTime = sourceDateTime.withZoneSameInstant(targetZone);
LocalTime targetTime = targetDateTime.toLocalTime();
System.out.println(targetTime);
Output when I ran today in America/Sao_Paulo time zone:
09:00
At this time of year (September), North American Eastern Time is at UTC offset -04:00 in most places including New York, and São Paulo is at -03:00, so 1 hour has been added to the time.
If instead I run the code in December, the output will be:
11:00
By then New York will be at offset -05:00 and São Paulo at -02:00 due to summer time, so 3 hours need to be added.
Link
Oracle tutorial: Date Time explaining how to use java.time.

- 81,772
- 15
- 137
- 161