I have a date in represented by the string "0002-01-04T00:49:40.000" i.e., a date in the year 2CE. I need to convert it to an instance ofjava.util.Date
by combining it with the timezone id "Etc/UTC". The following code shows how I do it:
public static Date toDate(LocalDateTime localDateTime, String timezoneId){
if(localDateTime == null) return null;
if(timezoneId != null) {
localDateTime.toDateTime(DateTimeZone.forID(timezoneId)).toDate();
} else {
return localDateTime.toDateTime().toDate()
}
}
But LocalDateTime.toDate()
doesn't work correctly. It adds +1 day to date.
"0002-01-04T00:49:40.000Z" ---> "Thu Jan 05 16:49:40 PST 2".