我有这个脚本,它给我从我输入的日期到当天的时间。
var millennium =new Date(2015, 6, 17)
today=new Date()
var one_day=1000*60*60*24
Math.ceil((today.getTime()-millennium.getTime())/(one_day)<2)
document.write(Math.ceil((today.getTime()-millennium.getTime())/(one_day))+
" day ago"
它工作正常,但我希望有一个简单的if / else语句,只在1天前将“days”更改为“day”。 我试过这个但是没有用:
var millennium =new Date(2015, 6, 17)
today=new Date()
var one_day=1000*60*60*24
if(Math.ceil((today.getTime()-millennium.getTime())/(one_day)==1){
document.write(Math.ceil((today.getTime()-millennium.getTime())/(one_day))+
" day ago")
}
else {
document.write(Math.ceil((today.getTime()-millennium.getTime())/(one_day))+
" days ago")
}
有什么想法吗? 谢谢!
答案 0 :(得分:1)
似乎是一些排版错误。
更正后的版本是:
var millennium =new Date(2015, 6, 17);
var today=new Date();
var one_day=1000*60*60*24;
var x = Math.ceil((today.getTime()-millennium.getTime())/one_day)
if(x == 1) {
document.write(x + " day ago");
}
else {
document.write(x + " days ago");
}