Skip to content

Instantly share code, notes, and snippets.

@sckirk
sckirk / formatDateAsUTC.java
Last active Oct 3, 2019 — forked from ebouchut/formatDateAsUTC.java
Format a Java Date as UTC String: yyyy-mm-dd HH:mm:ss'Z'
View formatDateAsUTC.java
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);
}