js获取当前(年/月/日)时间

获取当前时间

function timeDate(){
let timestamp = Date.parse(new Date());
let date = new Date(timestamp);
//获取年
let Y = date.getFullYear();
//获取月
let M = (date.getMonth() + 1 < 10 ? ‘0’ + (date.getMonth() + 1) : date.getMonth() + 1);
//获取当日
let D = date.getDate() < 10 ? ‘0’ + date.getDate() : date.getDate();
return (Y + ‘年’ + M + ‘月’ + D + ‘日’);
}

👋 感谢您的观看!

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享