Posts

Showing posts with the label java.util.calendar

Convert java Calendar object from local time to UTC

Convert java Calendar object from local time to UTC How do I convert a Java Calendar object from local time to UTC? This what I have tried: Calendar Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("UTC")); calendar.setTime(localDateTime.getTime()); SimpleDateFormat outputFmt = new SimpleDateFormat("MMM dd, yyy h:mm a zz"); String dateAsString = outputFmt.format(calendar.getTime()); System.out.println(dateAsString) Time is always displayed in MT not GMT. I want to store the calendar in UTC in a database (I'm not concerned with formatting or displaying the time). Possible duplicate of Convert Local time to UTC and vice versa – Shubhendu Pramanik Jun 30 at 12:48 3 Answers 3 ...