I tested Joda DateTime against java.util.Date
with UTC timezone, and I encountered an interesting case:
import org.joda.time.DateTime;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Date;
public class Main {
public static void main(String[] args) throws ParseException {
String dt = "2011-06-11T12:00:00Z";
String format = "yyyy-MM-dd'T'hh:mm:ss'Z'";
DateFormat df = new SimpleDateFormat(format);
df.setTimeZone(TimeZone.getTimeZone("UTC"));
Date d = df.parse(dt);
DateTime joda = new DateTime(dt);
// Output Sat Jun 11 05:00:00 PDT 2011
System.out.println(joda.toDate());
// Output Fri Jun 10 17:00:00 PDT 2011
System.out.println(d);
}
}
I wonder is this a bug to either one or I missed something important here?
(Edit: a clearer and more correct answer)
I believe it is because JODA and Java Date Format is treating "12" in 12-hour presentation differently. One of them treat it as midnight, while the other treat it as noon.
Change your input to 2011-06-11T01:00:00Z
will prove my hypothesis.
It is because, you are creating JODA time using the constructor of DateTime, which in turns parse your String using ISO format, for which use 24-hour format : Default format used by JODA, while the DateFormat you used to construct your Java Date is using hh
for hour field, which means 12-hour format. Therefore they interpret "12" differently: 12-hour format treat it as mid-night, while 24-hour treat it as noon.
Easiest change is to change the format to yyyy-MM-dd'T'HH:mm:ss'Z'
which use 24-hour presentation, then both of them works fine.