Convert date with ordinal numbers (11th, 22nd, etc.)

前端 未结 3 1605
闹比i
闹比i 2021-01-14 09:15

How to convert a date having the following format

September 22nd 2015, 10:39:42 am

to

09/22/2015 10:39:42

3条回答
  •  萌比男神i
    2021-01-14 10:00

    You need 2 date formats (and essentially you need 2 steps to perform the task) :

    1. Parsing the date September 22nd 2015, 10:39:42 am using a relevant date format string in order to get/convert it to date object
    2. Formatting the date object for your desired dd/MM/yyyy HH:mm:ss format to get the date output.

    I am leaving the implementation details for you to learn and explore.

    Tutorial for parsing & formatting using the new Date & Time API

提交回复
热议问题