js日期函数
以下是搜到的有用内容(以备查阅):
var nowDate = new Date();
nowDate.getYear(); //获取当前年份(2位)
nowDate.getFullYear(); //获取完整的年份(4位,1970-????)
nowDate.getMonth(); //获取当前月份(0-11,0代表1月)
nowDate.getDate(); //获取当前日(1-31)
nowDate.getDay(); //获取当前星期X(0-6,0代表星期天)
nowDate.getTime(); //获取当前时间(从1970.1.1开始的毫秒数)
nowDate.getHours(); //获取当前小时数(0-23)
nowDate.getMinutes(); //获取当前分钟数(0-59)
nowDate.getSeconds(); //获取当前秒数(0-59)
nowDate.getMilliseconds(); //获取当前毫秒数(0-999)
nowDate.toLocaleDateString(); //获取当前日期
nowDate.toLocaleTimeString(); //获取当前时间
nowDate.toLocaleString( ); //获取日期与时间
本文详细介绍了JavaScript中日期函数的各种用法,包括获取年、月、日、星期等基本信息的方法,以及如何获取具体的时间单位如小时、分钟、秒和毫秒等。此外还介绍了如何使用toLocaleString系列方法来格式化日期和时间。
1206

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



