当前位置:网站首页>js时间函数大全 详细的讲解 -----阿浩博客
js时间函数大全 详细的讲解 -----阿浩博客
2022-07-06 09:29:00 【冯浩(grow up)】
日期、时间对象
日期、时间对象是用来保存日期时间的,以特定的时间段保存时间,从1970年向前或者向后推285616年,UTC是格林尼治时间,又称世界统一时间。
实例化日期对象:var date = new Date ( );
一年的时间戳:var yearTimeStamp = 3652460601000;
设置日期时间 var date = new Date ( 2018,1,1 )
var date = new Date(“1/1/2018 11:30:30”);
1、组件方法
1、获取满年 getFullYear ( );
2、设置满年 setFullYear ( );
3、获取月份 getMonth ( ); 取值范围:0-11
4、设置月份 setMonth ( );
5、获取日期 getDate ( ); 取值范围:1-31
6、设置日期 setDate ( );
7、获取星期 getDay ( ); 取值范围:0-6
8、获取小时 getHours ( ); 取值范围:0-23
9、设置小时 setHours ( );
10、获取分钟 getMinutes ( ); 取值范围:0-59
11、设置分钟 setMinutes ( );
12、获取秒 getSeconds ( ); 取值范围:0-59
13、设置秒 setSeconds ( );
14、获取毫秒 getMillionSeconds ( ); 取值范围:0-999
15、设置毫秒 setMillionSeconds ( );
组件方法都有一个对应的UTC。
函数:获取指定年月的第一天是星期几
function getweek(year,month){
return new Date(year,month-1).getDay;
}console.log(getweek(2017,10));
2、时间定时器
1、设置时间定时器 setInterval ( function ( ){ },时间间隔(以毫秒计) );
2、清除时间定时器 clearInterval ( 定时器名称 );
边栏推荐
- Alice and Bob (2021 Niuke summer multi school training camp 1)
- 875. 爱吃香蕉的珂珂 - 力扣(LeetCode)
- Date plus 1 day
- C language must memorize code Encyclopedia
- Sword finger offer II 019 Delete at most one character to get a palindrome
- Opencv learning log 24 -- Hough transform 2 (maximum interval and minimum length can be limited)
- Advancedinstaller安装包自定义操作打开文件
- Luogu P1102 A-B number pair (dichotomy, map, double pointer)
- Bidirectional linked list - all operations
- window11 conda安装pytorch过程中遇到的一些问题
猜你喜欢
2078. Two houses with different colors and the farthest distance
Flask框架配置loguru日志庫
QT implementation window gradually disappears qpropertyanimation+ progress bar
Kubernetes cluster deployment
860. Lemonade change
QT有关QCobobox控件的样式设置(圆角、下拉框,向上展开、可编辑、内部布局等)
Discussion on QWidget code setting style sheet
QT simulates mouse events and realizes clicking, double clicking, moving and dragging
TCP's three handshakes and four waves
Installation and use of VMware Tools and open VM tools: solve the problems of incomplete screen and unable to transfer files of virtual machines
随机推荐
Quick to typescript Guide
Codeforces Round #798 (Div. 2)A~D
日期加1天
Opencv learning log 24 -- Hough transform 2 (maximum interval and minimum length can be limited)
Some problems encountered in installing pytorch in windows11 CONDA
1689. Ten - the minimum number of binary numbers
Li Kou - 298th weekly match
Remove the border when input is focused
AcWing——第55场周赛
计算时间差
MariaDB的安装与配置
Codeforces Round #802(Div. 2)A~D
Codeforces round 797 (Div. 3) no f
Share an example of running dash application in raspberry pie.
628. Maximum product of three numbers
Sanic异步框架真的这么强吗?实践中找真理
What is the difficulty of programming?
Opencv learning log 26 -- detect circular holes and mark them
“鬼鬼祟祟的”新小行星将在本周安全掠过地球:如何观看
Luogu P1102 A-B number pair (dichotomy, map, double pointer)