JS変換タイムスタンプは「ただいま」、「1分前」、「2時間前」、「1日前」などです.
2683 ワード
var minute = 1000 * 60;
var hour = minute *60;
var day = hour *24;
var week = day * 7;
var month = day * 30;
function getTimer(stringTime){
var time1 = new Date().getTime();//
console.log(time1);
var time2 = Date.parse(new Date(stringTime));//
console.log(time2);
var time = time1 - time2;
var result = null;
if(time < 0){
alert(" !");
}else if(time/month >= 1){
result = " " + parseInt(time/month) + " !";
}else if(time/week >= 1){
result = " " + parseInt(time/week) + " !";
}else if(time/day >= 1){
result = " " + parseInt(time/day) + " !";
}else if(time/hour >= 1){
result = " " + parseInt(time/hour) + " !";
}else if(time/minute >= 1){
result = " " + parseInt(time/minute) + " !";
}else {
result = " !";
}
console.log(result);
}
getTimer("2015-07-20 15:21:12");
転載先:https://www.cnblogs.com/chengkun101/p/4702764.html