1 想要得到2017年2月2日,怎么做呢?
var date1 = new Date('2017/2/2'); var date2 = new Date(2017, 1, 2); document.write(date1+"<br>"); document.write(date2);
2 Date.now
var sum = 0; var result = 0; var start = Date.now(); for (var i = 1; i < 1000001; i++) { sum += i; } var end = Date.now(); var result = end - start; document.write("sum is: " + sum + "<br>"); document.write("take time is: " + result + "<br>");
3 比较大小:怎么比较两个日期的大小呢?
var date1 = new Date(2017, 0, 1); var date2 = new Date(2017, 1, 1); document.write(date1 < date2);