javascript获取当前时间(年-月-日 时:分:秒)
var getCurrentDateTime = function() { //获取当前时间
var now= new Date();
var _month = ( 10 > (now.getMonth()+1) ) ? '0' + (now.getMonth()+1) : now.getMonth()+1;
var _day = ( 10 > now.getDate() ) ? '0' + now.getDate() : now.getDate();
var _hour = ( 10 > now.getHours() ) ? '0' + now.getHours() : now.getHours();
var _minute = ( 10 > now.getMinutes() ) ? '0' + now.getMinutes() : now.getMinutes();
var _second = ( 10 > now.getSeconds() ) ? '0' + now.getSeconds() : now.getSeconds();
return now.getYear() + '-' + _month + '-' + _day + ' ' + _hour + ':' + _minute + ':' + _second;
};
本文介绍了一个JavaScript函数,用于获取并格式化当前日期和时间到'年-月-日 时:分:秒'的字符串形式。该方法适用于需要在前端显示精确时间的应用场景。
3万+

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



