很常见的需求
两个函数
//js获取当前时间 function getNowDate() { var myDate = new Date; var year = myDate.getFullYear(); //获取当前年 var mon = myDate.getMonth() + 1; //获取当前月 var date = myDate.getDate(); //获取当前日 var hours = myDate.getHours(); //获取当前小时 var minutes = myDate.getMinutes(); //获取当前分钟 var seconds = myDate.getSeconds(); //获取当前秒 var now = year + "-" + mon + "-" + date + " " + hours + ":" + minutes + ":" + seconds; return now; } //获取当前时间戳 function getTimestamp() { return new Date(getNowDate()).getTime(); }