javatimezonejava-timezoneid

What's the difference between TimeZone and ZoneId?


What is the difference between the java.util.TimeZone and java.time.ZoneId classes in JDK?

Is there more information about the differences between the two to help me decide which class I should use in my project?


Solution

  • All the "old" time-related types (java.util.Calendar, java.util.Date, java.util.TimeZone etc) are still present and may well never be deprecated because so much code depends on them. If those types were deprecated as a whole (rather than just the particularly bad parts of them, such as the Date(int, int, int) constructor) I suspect it would cause so many deprecation warnings (and the work in migration would be so large) that almost all companies would just turn off or ignore warnings, instead of migrating to java.time.

    However, for any new code (or at the very least whole new projects) it's a much better idea to use java.time and related packages for everything to do with handling time - including using ZoneId instead of TimeZone.