I am trying the format the date timestamp including a time zone with a colon. And I did several experiments to get the result. Here's what I found.
Date date = new Date();
String zonedDateTimeFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX";
SimpleDateFormat sdf = new SimpleDateFormat(zonedDateTimeFormat);
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
System.out.println(sdf.format(new Date(date.getTime())));
If I set the time zone as UTC, I will get a timestamp like this:
2020-11-03T21:14:07.449Z
But If the time zone is not UTC
Date date = new Date();
String zonedDateTimeFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSXXX";
SimpleDateFormat sdf = new SimpleDateFormat(zonedDateTimeFormat);
System.out.println(sdf.format(new Date(date.getTime())));
The timestamp would be like this: 2020-11-03T22:19:43.804+01:00
I am wondering if it is possible to get a timestamp within UTC time zone like: 2020-11-03T21:14:07.449+00:00 instead of ending with a uppercase Z?