Convert Date from one format to another format in JavaScript

后端 未结 4 1508
说谎
说谎 2020-12-03 18:40

I have a string of a date in javascript in format #1. I need to convert it to format #2.

The problem starts when one format is \"dd/mm/yy\" and the other is \"mm/dd/

4条回答
  •  我在风中等你
    2020-12-03 19:15

    You should look into momentjs, which is a javascript date/time library. With that, you can easily convert between dates of different format. In your case, it would be:

    string newDate = moment(currentDate, currentFormatString).format(newFormatString)

    For example, moment("21/10/14", "DD/MM/YY").format("MM/DD/YY") would return "10/21/14"

提交回复
热议问题