封装一个时间戳
主要应用:更新博客,评论等尾部带时间
function dateStr(d,sign){
if(!sign){
sign='-'
}else{
sign = sign;
}
let year = d.getFullYear(),
month = d.getMonth()+1,
day = d.getDate(),
hours = d.getHours(),
minutes = d.getMinutes(),
seconds = d.getSeconds();
return year + sign + mendZero(month) + sign + mendZero(day)
+ mendZero(hours)+sign + mendZero(minutes) + sign + mendZero(seconds);
}
字符串补零
function mendZero(num){
return num = num < 10 ? '0' + num : num;
}