参照ドキュメント:http://www.w3school.com.cn/js/jsref_obj_date.asp
function getSysTimestamp() {
var now = new Date();
var date=now.getDate();
var month=now.getMonth()+1;
var year=now.getYear();
var timestr;
timestr = year;
timestr += ((month<10)?"0":"")+month;
timestr += ((date<10)?"0":"")+date;
var hours = now.getHours();
var minutes = now.getMinutes();
var seconds = now.getSeconds();
var milseconds = now.getMilliseconds();
timestr += ((hours<10)?"0":"")+hours;
timestr += ((minutes<10)?"0":"")+minutes;
timestr += ((seconds<10)?"0":"")+seconds;
timestr += milseconds;
return timestr;
}
本文介绍了一种使用JavaScript获取当前系统日期及时间的方法,并将其格式化为特定字符串形式的时间戳。该方法首先创建了一个新的Date对象来获取当前时间,然后分别获取年、月、日、小时、分钟、秒及毫秒等信息,最后将这些信息拼接成一个包含年月日时分秒及毫秒的字符串。

被折叠的 条评论
为什么被折叠?



