new Date的所有方法
时间: 2024-06-12 11:11:09 浏览: 13
new Date() 是 JavaScript 中用于创建日期对象的构造函数,它有很多方法可以用来获取和设置日期、时间等信息。以下是 new Date() 的所有方法:
1. getDate():获取当前日期是当前月份的第几天(1-31)。
2. getDay():获取当前日期是星期几(0-6,0 表示星期日)。
3. getFullYear():获取当前日期的年份(四位数)。
4. getHours():获取当前时间的小时数(0-23)。
5. getMilliseconds():获取当前时间的毫秒数(0-999)。
6. getMinutes():获取当前时间的分钟数(0-59)。
7. getMonth():获取当前日期的月份(0-11,0 表示一月)。
8. getSeconds():获取当前时间的秒数(0-59)。
9. getTime():获取当前日期对象距离 1970 年 1 月 1 日 00:00:00 UTC 的毫秒数。
10. getTimezoneOffset():获取当前时区与 UTC 时间相差的分钟数。
11. setDate(date):设置当前日期是当前月份的第几天(1-31)。
12. setFullYear(year, month, date):设置当前日期的年份、月份和日期。
13. setHours(hour, min, sec, ms):设置当前时间的小时数、分钟数、秒数和毫秒数。
14. setMilliseconds(ms):设置当前时间的毫秒数。
15. setMinutes(min, sec, ms):设置当前时间的分钟数、秒数和毫秒数。
16. setMonth(month, date):设置当前日期的月份和日期。
17. setSeconds(sec, ms):设置当前时间的秒数和毫秒数。
18. setTime(time):设置当前日期对象距离 1970 年 1 月 1 日 00:00:00 UTC 的毫秒数。
19. toDateString():将当前日期对象转换为字符串,格式为 "Day Month Date Year",例如 "Tue Aug 24 2021"。
20. toISOString():将当前日期对象转换为 ISO 格式的字符串,例如 "2021-08-24T08:00:00.000Z"。
21. toJSON():将当前日期对象转换为 JSON 格式的字符串。
22. toLocaleDateString():将当前日期对象转换为本地日期字符串,例如 "2021/8/24"。
23. toLocaleTimeString():将当前日期对象转换为本地时间字符串,例如 "08:00:00"。
24. toLocaleString():将当前日期对象转换为本地日期和时间字符串,例如 "2021/8/24 上午8:00:00"。
25. toString():将当前日期对象转换为字符串,格式为 "Day Month Date Year HH:mm:ss GMT+0800 (中国标准时间)"。
26. toTimeString():将当前日期对象转换为时间字符串,例如 "08:00:00 GMT+0800 (中国标准时间)"。
27. toUTCString():将当前日期对象转换为 UTC 时间字符串,例如 "Tue, 24 Aug 2021 00:00:00 GMT"。
28. UTC(year, month, date, hour, min, sec, ms):根据 UTC 时间设置当前日期对象的年份、月份、日期、小时数、分钟数、秒数和毫秒数。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)