How To Convert Date To Format “Yyyy-Mm-Ddthh:Mm:Ss-Hh:Mm”?

200    Asked by Dhruvtiwari in Java , Asked on Aug 2, 2023

I need to convert Date from “YYYY-MM-DD” to ‘YYYY-MM-DDThh:mm:ss-hh:mm” format. How to do so?
By trying the “yyyy-Mm-dd’ T ‘ HH:mm:ss.SSSXXX” pattern, it is possible to change Date from “YYYY-MM-DD” to “YYYY-MM-DDThh:mm:ss-hh:mm” format like the one given below:

Date d = System.today(); Datetime myDT = datetime.newInstance(d.year(), d.month(),d.day()); String myDate = myDT.format('yyyy-MM-dd'T'HH:mm:ss.SSSXXX');
"YYYY-MM-DDThh:mm:ss-hh:mm" is ISO 8601 format. Check this link- https://www.w3.org/TR/xmlschema-2/#isoformats for ISO formats.
Refer http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html for formatting and parsing dates.
Different time and date patterns
Date and time patterns can be traced from the example below:
yyyy-MM-dd HH:mm:ss.SSSXXX
1999-03-22 05:06:07.000+01:00
yyyy-MM-dd HH:mm:ss,SSSXXX
1999-03-22 05:06:07,000+01:00
yyyy-MM-dd'T'HH:mm:ssXXX
1999-03-22T05:06:07+01:00
yyyy-MM-dd HH:mm:ssXXX
1999-03-22 05:06:07+01:00

The Java Online Certification Training offered at JanBask Training provides experience like offline classes to help candidates master the concepts of Java in a better way to face the tough job market scenario. The course guarantees job success and lets you qualify the certification exam through intensive, and expert-led virtual sessions and hands-on practical assignments. The course will teach you to create and configure the Java codes to help you gather, extract, and examine the data relevant to the customer base. Furthermore, JanBaskTraining helps you get job-ready and face the tough competitive market with confidence.



Your Answer

Interviews

Parent Categories