-
-
Save sckirk/9322db3dcf4b3f91d19021e3e13d0853 to your computer and use it in GitHub Desktop.
Format a Java Date as UTC String: yyyy-mm-dd HH:mm:ss'Z'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
publicString formatDateAsUTC(Date date) { | |
Calendar calendar = Calendar.getInstance(); | |
calendar.setTime(date); | |
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss'Z'"); | |
sdf.setTimeZone(TimeZone.getTimeZone("UTC")); | |
return sdf.format(date); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated bug: I was playing around with this Java code and was confused why the minutes were showing up as the month. https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html confirmed the month needs to be 'M' instead of 'm'.