[Solved] Convert string to date format using javascript


A little workaround could be the following, but if you have to manipulate dates a lot, I strongly recommend you to use the Moment.js library:

https://momentjs.com/

var strDate = "2016-11-20";
var utcDate = new Date(strDate).toUTCString();
var convertedDate= utcDate.substring(utcDate.lastIndexOf(", ") + 1, utcDate.lastIndexOf(" 00:"));
console.log(convertedDate.trim().replace(/\s/g, '-'));

Pay attention that the implementation of this method may change depending on the platform. Here from the official doc:

The value returned by toUTCString() is a human readable string in the
UTC time zone. The format of the return value may vary according to
the platform. The most common return value is a RFC-1123 formatted
date stamp, which is a slightly updated version of RFC-822 date
stamps.

3

solved Convert string to date format using javascript