js needs to convert the timestamp into a normal format, which may not be used under normal circumstances.
Let’s look at the first one first
function getLocalTime(nS) {
return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:d {1,2}$/,' ');
}
alert(getLocalTime(1293072805));
The result is
December 23, 2010 10:53
The second type
function getLocalTime(nS) {
return new Date(parseInt(nS) * 1000).toLocaleString().substr(0,17)}
alert(getLocalTime(1293072805));
If you want to get it like this What to do with the format?
2010-10-20 10:00:00
Look at the code below
function getLocalTime(nS) {
return new Date(parseInt(nS) * 1000).toLocaleString().replace(/year|month/g, "-").replace(/ day/g, " ");
}
alert(getLocalTime(1177824835));
can also be written like this
function formatDate(now) {
var year=now.getYear();
var month=now .getMonth() 1;
var date=now.getDate();
var hour=now.getHours();
var minute=now.getMinutes();
var second=now. getSeconds();
return year "-" month "-" date " " hour ":" minute ":" second;
}
var d=new Date(1230999938);
alert( formatDate(d));
The problem is solved
It should be noted that
do not pass the Date (such characters in the string), you must process them first, so
which is very convenient to handle can be processed using the replace method
as follows:
replace("/Date(","").replace(")/","");