下面这个函数,请大家帮我具体解释下意思,小弟刚学js不懂,请各位帮忙详细解释下,越详细越好,谢谢大家了function time(nS) {
return new Date(parseInt(nS) * 1000).toLocaleString().replace(/年|月/g,"-").replace(/日/g,""); }
return new Date(parseInt(nS) * 1000).toLocaleString().replace(/年|月/g,"-").replace(/日/g,""); }
toLocaleString() // 得到这个日期字符串,中文操作系统就会显示如:2010年1月1日 12:00:00
.replace(/年|月/g,"-") //将上面的字符串中的“年”和“月”2个字符转换成“-”,变成:2010-1-1日 12:00:00
.replace(/日/g,"") // 再将上一步的字符串中的“日”替换成“”(空),变成:2010-1-1 12:00:00