欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

js时间的应用(再看看前面,会发现不一样的)

程序员文章站 2022-05-21 14:14:31
1、年份(1970-) 获取 date.getFullYear(); 设置 date.setFullYear(2016); 2、月份(0-11) 0代表1月 获取 date.getMonth() 设置 date.setMonth(0);//设置月份为1月 3、日(1-31) 获取 date.getD ......
1、年份(1970-)
获取 date.getfullyear();
设置 date.setfullyear(2016);

2、月份(0-11) 0代表1月
获取 date.getmonth()
设置 date.setmonth(0);//设置月份为1月

3、日(1-31)
获取 date.getdate()
设置 date.setdate(18)//设置日期为18日
 
特殊:设置天为0,存储的是上个月的总天数
date.setdate(0);
date.getdate();//获取上个月的总天数

4、星期(0-6) 0代表周日
获取 date.getday();

不可设置星期

5、小时(0-23)
获取:date.gethours()
设置:date.sethours(18);

6、分钟(0-59)
获取:date.getminutes();
设置:date.setminutes(59);

7、秒(0-59)
获取:date.getseconds();
设置:date.setseconds(20);

8、毫秒
获取:date.getmilliseconds();
设置:date.setmilliseconds(890);

get获取 set设置(返回的都是时间戳)