utc date format java code example
Example 1: new date to utc string java
myJavaUtilDate.toInstant().toString()
Example 2: java get date in utc
OffsetDateTime now = OffsetDateTime.now(ZoneOffset.UTC);
System.out.println(now);
Example 3: java get date in utc
private static Date getCurrentUtcTime() throws ParseException {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss");
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
SimpleDateFormat localDateFormat = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss");
return localDateFormat.parse( simpleDateFormat.format(new Date()) );
}