The documentation for Date.getTimezoneOffset says:
Deprecated. As of JDK version 1.1, replaced by
-(Calendar.get(Calendar.ZONE_OFFSET) + Calendar.get(Calendar.DST_OFFSET)) / (60 * 1000).
Why was it deprecated? Is there a shorter way (Apache Commons?) to get the offset from UTC in hours/minutes? I have a Date object … should I convert it to JodaDate for this?
And before you ask why I want the UTC offset – it’s just to log it, nothing more.
There are 2 questions here.
I think it is because they actually deprecated nearly all methods of Date and moved their logic to calendar. We are expected to use generic
setandgetwith the parameter that says which specific field we need. This approach has some advantages: less number of methods and the ability to run setters in a loop passing a different field each time. I personally used this technique a lot: it makes code shorter and easier to maintain.Calendar.get(Calendar.DST_OFFSET)comparing toCalendar.getTimeZoneOffset()As far as I can see the difference is 6 characters.
Joda is a very strong library and if you really have to write a lot of sophisticated date manipulation code switch to it. I personally use the standard
java.util.Calendarand don’t see any reason to use external libraries: good old calendar is good enough for me.