Given this code...
String date = "11:00 AM";
SimpleDateFormat sdf = new SimpleDateFormat("h:mm a");
sdf.setTimeZone(TimeZone.getTimeZone("US/Eastern")); // --> should be GMT-4
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
Date parse = sdf.parse(date); // -- gives Thu Jan 01 16:00:00 GMT 1970
Why does date parsing give me 16:00 and not 15:00?
You cannot use java.util.Date to store time only. It will assign the 1970 year, which in some cases is incorrect. I would recommend to use org.joda.time.LocalTime for it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With