The first method: (This method is only accurate to seconds)
var timestamp = (new Date());
Result: 1280977330000
The second method:
var timestamp = (new Date()).valueOf();
Result: 1280977330748
The third method:
var timestamp=new Date().getTime();
Result: 1280977330748
The first: The timestamp obtained is to change milliseconds to 000 display, because this method is only accurate to seconds
The second and third are to obtain the timestamp of the current millisecond.
Add a problem encountered
var a=(new Date()).toLocaleDateString()//Get the current date a =(/\//g,'-');//Replace 2017/05/03 as 2017-05-03var nowdate= (new Date(a))/1000;//Turn the current date into a time stampvar wdate=(new Date())/1000;//Turn database date into time
How to convert js timestamps to date format
//The first typefunction getLocalTime(nS) { return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/,' '); } alert(getLocalTime(1293072805)); //The result is December 23, 2010 at 10:53//The second typefunction getLocalTime(nS) { return new Date(parseInt(nS) * 1000).toLocaleString().substr(0,17) } alert(getLocalTime(1293072805)); //The third format is: 2010-10-20 10:00:00 function getLocalTime(nS) { return new Date(parseInt(nS) * 1000).toLocaleString().replace(/Year|moon/g, "-").replace(/day/g, " "); } alert(getLocalTime(1177824835));
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.