当前位置:网站首页>JS 获取当前日期与时间
JS 获取当前日期与时间
2022-07-19 05:06:00 【实习森】
一、获取当前日期与时间
const t = newDate(); // Tue Jul 05 2022 17:35:44 GMT+0800 (中国标准时间)
1 获取完整的年份(4位,1970—)
t.getFullYear(); // 2022
2 获取当前年份(2位)
t.getYear(); // 122 (2022-1900)
3 获取当前月份(0-11,0表示1月)
t.getMonth(); // 6
4 获取当前日(1-31)
t.getDate(); // 5
5 获取当前星期几(0-6,0代表星期天)
t.getDay(); // 2
6 获取当前时间(从1970.1.1开始的毫秒数)
t.getTime(); // 1657014040374
7 获取当前小时数(0-23)
t.getHours(); // 17
8 获取当前分钟数(0-59)
t.getMinutes(); // 40
9 获取当前秒数(0-59)
t.getSeconds(); // 40
10 获取当前毫秒数(0-999)
t.getMilliseconds(); // 200
11 获取当前日期与时间字符串
t.toLocaleString(); // '2022/7/6 09:51:14'
12 获取当前日期字符串
t.toLocaleDateString(); // '2022/7/6'
13 获取当前时间字符串
t.toLocaleTimeString(); // '09:51:14'
边栏推荐
猜你喜欢
4.MVC模型和MVVM模型
数据在内存中的存储
【测试技术-自动化测试-pytest】Pytest基础总结
15.内置指令
1. Realize MVVM bidirectional data binding stepping pit - infinite trigger get, set
83-局部组件的复用[父传子]
Skillfully solve Young's matrix
Chapter 62: blue screen crash when running vs program on win10
C language to achieve basic version of mine sweeping
ES6语法(let、const、var 的区别、解构赋值、箭头函数、剩余参数、Array 的扩展方法)
随机推荐
3. Data binding
使用nvm use出现exit status 1与exit status 145乱码
66-[重点]v-for指令的key属性
15.内置指令
[调试bug]JS:getFullYear is not a function
Supplement: ES6 knowledge points
宏任务、微任务 和 事件循环机制
学习日记4-程序结构和控制语句
Study diary - pointer topic
Special topic of structure
77 global customization instruction
数据在内存中的存储
补充:ES6知识点
6. Implementation of bidirectional binding (V-model)
75-局部自定义指令——bind和update方法
92 value transfer between brother components
Learning diary 3- input and output of data
通过调试发现程序死循环的原因
继承(子构造函数继承父构造函数中的属性)
我的第一篇博客