我的问题很简单,但我很难解决。基本上,我将从数据库中的new Date().getTime()
方法接收到的数字存储在数据库中,然后在前一段时间的函数中使用该字符串。该函数运行良好,但我不知道如何将字符串转换回DD-MM-YYYY ; h:m:s
格式
我以前的功能:
<script>
$(document).ready(function() {
var db_time = //the string from the database;
var c_db_time = db_time/1000;//remove the milli seconds
function ago()
{
var current_time = new Date().getTime()/1000;//remove the milli seconds
var dif = Math.round(current_time - c_db_time);
if(dif<60)//one minute ago
{
if(dif<=10){$(".elapsed_time").html("just now");}
else{var ago = dif;$(".elapsed_time").html(ago+"sec ago");}
}
else if(dif<3600)//one hour ago
{
var ago = Math.round(dif/60);
$(".elapsed_time").html(ago+"min ago")
}
else if(dif<86400)//one day ie.24hours ago
{
var ago = Math.round(dif/3600);
$(".elapsed_time").html(ago+"hr ago");
}
else if(dif<604800)// one week ago
{
var ago = Math.round(dif/86400);
$(".elapsed_time").html(ago+"Day ago");
}
}
setInterval(ago,1000);//run the script every 1 sec
});
</script>
注意:我到处研究谷歌和堆栈溢出,但找不到适合我的答案。