I want to convert a String Date into a DateTime object for a particular timezone and in a particular format. How can I do it ?
String Date can be in any format used in the world. Example MM-DD-YYYY, YYYY-MM-DD, MM/DD/YY
, MM/DD/YYYY etc. TimeZone can be any legal timezone specified by the user.
Example – convert YYYY-MM-DD into MM/DD/YY for the Pacific Timezone.
Use
DateTimeFormatterBuilderto build a formatter that is able to parse/format multipleDateTimeFormats, and set the resultingDateTimeFormatterto use a specifiedDateTimeZone:To format a given
DateTimeyou can just usedttm1.toString("yyyy-MM-dd")).