Date Conversion
Description
Date type has three buildin methods to convert date value to string and milliseconds.
- toLocaleString() returns the date and time in a format appropriate for the locale.
- toString() returns the date and time with time-zone information.
- valueOf() returns the milliseconds representation of the date.
Example
var date1 = new Date(2007, 0, 1); //"January 1, 2007"
var date2 = new Date(2007, 1, 1); //"February 1, 2007"
//w w w . j a va2s . c o m
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.