var now = new Date();
var Year = now.getFullYear(); //获取年
var Month = now.getMonth(); //月
var Date = now.getDate(); //日
var Day = now.getDay(); //当日星期数
var Hours = now.getHours(); //小时
var Minutes = now.getMinutes(); //分钟
var Seconds = now.getSeconds(); //秒
console.log(Year);
console.log(Month);
console.log(Date);
前端获取当前的年月日时分秒
最新推荐文章于 2024-11-25 16:20:58 发布
这篇博客展示了如何使用JavaScript获取当前日期和时间,包括年、月、日、星期、小时、分钟和秒。通过varnow=newDate()初始化日期对象,然后分别用getFullYear()、getMonth()、getDate()、getDay()、getHours()、getMinutes()和getSeconds()方法获取各个时间单位。这是一个基础的JavaScript时间处理实例。
6940

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



