Date type has three buildin methods to convert date value to string and milliseconds.
var date1 = new Date(2007, 0, 1); //"January 1, 2007"
var date2 = new Date(2007, 1, 1); //"February 1, 2007"
console.log(date1.toString());
console.log(date1.toLocaleString());
console.log(date1 < date2); //true, calling valueOf() from Date
console.log(date1 > date2); //false, calling valueOf() from Date
The code above generates the following result.
There are several Date type methods to format the date as a string.
var date1 = new Date(2007, 0, 1); //"January 1, 2007"
console.log(date1.toDateString());
console.log(date1.toTimeString());
console.log(date1.toLocaleDateString());
console.log(date1.toLocaleTimeString());
console.log(date1.toUTCString());
The code above generates the following result.