I parse this date “22/11/11” into a DateTime object called s. When I do s.getDayOfMonth() it gives me 22 which is right. However, when I convert the DateTime object to a Date object and try to get the date using s.toDate().getDate() it returns 24 which is not right. Does anyone have an idea why is this happening ?
Share
The Joda-Time
DateTime.toDate()method converts to ajava.util.Datewith the same millisecond instant. Thejava.util.Date.getDate()method uses the local default time-zone to return its value, whereasDateTime.getDayOfMonth()uses the time-zone stored in theDateTimeobject. If the two time-zones are different, you may see a difference, explaining the 22/24 you observe.To understand further, print the time-zone of the
DateTime, and the default Java zoneTimeZone.getDefault()used byjava.util.Date.