Convert a date string to a Date (Date) object

Date string: 2018-02-07 17:09

var dateString = '2018-02-07 17:09';
date = new Date(dateString.replace(/-/g, "\/"));
console.trace(date, date.constructor);// Wed Feb 07 2018 17:09:00 GMT+0800 (CST) ƒ Date() { [native code] }

 This example shows that the constructor of the JavaScript Date class supports input strings, but the format must be: 'yyyy/MM/dd HH:mm:ss' format.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326293610&siteId=291194637