You can use SimpleDateFormat.
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
df.setTimeZone(TimeZone.getTimeZone("UTC"));
System.out.println(df.format(new Date()));
Output:
2010-02-14T06:38:48.920Z
Here you manually set the time zone for the date format in UTC.
source
share