Date-time objects have no “format”
I've got a Calendar that comes back in a following format (it's in Java Calendar type): 2020-02-15T00:00:00.
No, you don’t.
A Calendar
object has no format. Only text representing a date-time value has a format.
following Calendar like this one and persist the Calendar type: Mon Nov 05 2018 14:08:58 GMT+0000 (Greenwich Mean Time)?
There is no such thing as a Calendar
object with that format, as a Calendar
has no format and is not text.
Learn to search Stack Overflow before posting. This has been covered many times already.
java.time
The terrible Calendar
class was supplanted years ago by the java.time class with the adoption of JAR 310. Never use Calendar
.
Get the current time in UTC with the OffsetDateTime
class.
OffsetDateTime odt = OffsetDateTime.now( ZoneOffset.UTC ) ;
To generate text in standard ISO 8601 format, call toString
. To persist a date-time value as text, use these formats – that’s why they were invented.
To generate text in another format, use the DateTimeFormatter
class. This has been covered many many times, so search Stack Overflow.
Convert
If given a GregorianCalendar
object, convert immediately to a ZonedDateTime
object by calling new methods added to the old legacy classes.
ZonedDateTime zdt = myGregCal.toZonedDateTime() ;
Cast if need be.
ZonedDateTime zdt = ( (GregorianCalendar) myCal ).toZonedDateTime() ;
Then use DateTimeFormatter
to generate text in your desired format.