当前位置:网站首页>Constructor_ Date constructor
Constructor_ Date constructor
2022-07-24 05:30:00 【Good [email protected]】
Date
Date Constructors
effect
Date It's a constructor , But it can also be called directly ;
Use new Key word call : Create a Date Instance object , This instance presents a moment in time ;
Call directly : The return value is a string , Present a moment in time ;
grammar
- new Date([value])
- new Date()
- No parameters passed , So the newly created Date Object represents the date and time of the instantiation time ;
- new Date(value)
- The parameter is timestamp : From 1970 year 1 month 1 Japan 00:00:00 UTC(the Unix epoch) Milliseconds since ( That is to say 1970 year 1 month 1 The conversion time between the sum of the number of milliseconds of the day and the number of milliseconds of the parameter )
- 1 second == 1000 millisecond
- new Date(year,mounth,[date],[hours],[minutes],[seconds],[milliseconds])
- The parameters are date and time members , Year and month are required parameters , The rest are optional parameters :
- mounth Choose as 0-11, in other words 0 Express 1 month
- new Date()
- Be careful : If the parameter is a string , The resolution is not local time but UTC Time
- new Date(‘1655953575839’)
- new Date(‘2022-1-1’)
Methods of constructors
- Get the timestamp of the current date
- Date.now()
- Date.parse() -String type
The method of prototype chain
[1] Gets the year of the specified date 、 month 、 Japan 、 when 、 branch 、 second 、 millisecond ;
- year :getFullYear()
- month :getMonth()
- Japan :getDate()
- when :getHours()
- branch :getMinutes()
- second :getSeconds()
Get the day of the week that the specified date belongs to
- getDay()
- The return value is 0-6,0 Sunday ;
Get the timestamp of the specified date
- getTime()-Number type
- valueOf()-Number type
Common logic
[1] Today, ( Including today ) Not optional after date
// now() Functions are constructors Date Methods ---> You can get the number of seconds of the current time
// The number of milliseconds in a day is 24*3600*1000= 86400000 = 8.64*10 Of 7 Power = 8.64e7
Date.now() - 8.64e7
[2] Today, ( Not including today ) After date is not optional
Date.now() - 8.64e6
[3] Convert time to timestamp
// Get the timestamp of the current time -Number data type
Date.now()
// Get the timestamp of the specified time -Number data type
Number(new Date())
new Date().getTime()
new Date().valueOf()
// Get the timestamp of the current time -string data type
Date.parse()
[3] Convert timestamp to time
const date = new Date(1655968066474)
// error - Because the acquisition of month is 0-11, Normal month is 1-12, Normally, you should add 1
console.log(`${
date.getFullYear()}-${
date.getMonth()}-${
date.getDate()}`)
console.log(`${
date.getFullYear()}-${
date.getMonth()+1}-${
date.getDate()}`)
版权声明
本文为[Good [email protected]@@]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/205/202207240515392330.html
边栏推荐
猜你喜欢
随机推荐
空杯心态,重新开始
csgo部分常用服务器指令与一些绑定指令整理
Geoserver REST API功能解析
JS输出字符串中出现最多次数的字符
Relationship between sample and population in Statistics: sample success ratio + central limit theorem (sample mean)
special effects - 蜘蛛网背景特效
【STL】Map &unordered_ map
闲来写博~简单说说let和var和const
Neo4j修改标签名
reflex
Generics and annotations
7. 在屏幕上绘制一条贝塞尔曲线,并用反走样技术对曲线进行平滑处理。
Handwritten ORM framework
ros启动非本机节点
canvas - 圆形
C语言进阶篇 七.程序的编译和预处理
构造函数_Date构造函数
gdb调试core/dump
这是第一篇
JS - 数值处理(取整、四舍五入、随机数等)









