当前位置:网站首页>JS获取当前时间的年、月、日、时间等

JS获取当前时间的年、月、日、时间等

2022-08-10 04:00:00 weixin_43923808

var date = new Date();

date .getYear(); //获取当前年份(2位)

date .getFullYear(); //获取完整的年份(4位)

date .getMonth(); //获取当前月份(0-11,0代表1月)

date .getDate(); //获取当前日(1-31)

date .getDay(); //获取当前星期X(0-6,0代表星期天)

date .getTime(); //获取当前时间(从1970.1.1开始的毫秒数)

date .getHours(); //获取当前小时数(0-23)

date .getMinutes(); //获取当前分钟数(0-59)

date .getSeconds(); //获取当前秒数(0-59)

date .getMilliseconds(); //获取当前毫秒数(0-999)

date .toLocaleDateString(); //获取当前日期

var mytime=date .toLocaleTimeString(); //获取当前时间

date .toLocaleString( ); //获取日期与时间

原网站

版权声明
本文为[weixin_43923808]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_43923808/article/details/126243587