当前位置:网站首页>JS foundation 6
JS foundation 6
2022-06-28 10:53:00 【Programmer community】
Date time object Date
establish
- Automatically get time
var date=new Date()
- Create the specified date and time
var date=new Date('2021,3,18 00:00:00')
notes :
It must be a string type
The value passed in is in years , month , Japan , when , branch , second , There is no zero filling processing
Method
| Method | meaning |
|---|---|
| getTime() | Returns the number of milliseconds of the date |
| getFullYear() | return 4 Digit year |
| getMonth() | Returns the month of the date |
| getDate() | Returns the day of the date |
| getDay() | Returns the day of the week of the date |
| getHours() | Returns the hour in the date |
| getMinutes() | Returns the minute in the date |
| getSeconds() | Returns the second in the date |
| getMilliseconds() | Returns the number of milliseconds in the date |
notes :
- From the month 0 Start counting
- getDay() in 0 Means Sunday , The other is constant
Calculate the difference between two dates
- The quasi change date is milliseconds
notes : Milliseconds is the time from the date to the origin of computer time (1970 year 1 month 1 Japan 0 when 0 branch 0 second ) - Millisecond difference
- transformation
<script> function timeDiffer(m,n){
var date1=new Date(m)
var date2=new Date(n)
// Calculate the milliseconds of the difference between two dates
var differdate=date1.getTime()-date2.getTime()
// How many milliseconds a year
var yearTime=1000*60*60*24*365
// How many years to round down
var year = Math.floor(differdate/yearTime)
console.log(year)
// How many milliseconds a month
var monthTime=1000*60*60*24*30
// The millisecond difference between the two dates minus the millisecond of last year
var differmonth=differdate-year*yearTime
var month =Math.floor(differmonth/monthTime)
console.log(month)
var dayTime=1000*60*60*24
var differday=differmonth-month*monthTime
var day=Math.floor(differday/dayTime)
console.log(day)
var hourTime=1000*60*60
var differhour=differday-day*dayTime
var hour=Math.floor(differhour/hourTime)
console.log(hour)
var minuteTime=1000*60
var differMinute=differhour-hour*hourTime
var minute=Math.floor(differMinute/minuteTime)
console.log(minute)
var secondTime=1000
var differSecond=differMinute-minute*minuteTime
var second=Math.floor(differSecond/secondTime)
console.log(second)
}
timeDiffer('2022-4-18 11:34:02','2022-2-18 8:30:00')
</script>
Date formatting method
| Method | meaning |
|---|---|
| toString | Returns the date and time with time zone information |
| toDateString | Show the day of the week in the date , month , Japan , year |
| toTimeString | Display time , branch , second , And time zone |
| toLocaleDateString | Show the day of the week in the date , month , Japan , year |
| toLocaleTimeString | Display time , branch , second |
| toUTCString | Show complete UTC date |
<script>
var date=new Date()
var date1=date.toString()
var date2=date.toDateString()
var date3=date.toTimeString()
var date4=date.toLocaleDateString()
var date5=date.toLocaleTimeString()
var date6=date.toUTCString()
console.log(date)
// result Sat Mar 19 2022 10:21:30 GMT+0800 ( China standard time )
console.log(date1)
// result Sat Mar 19 2022 10:21:30 GMT+0800 ( China standard time )
console.log(date2)
// result Sat Mar 19 2022
console.log(date3)
// result 10:21:30 GMT+0800 ( China standard time )
console.log(date4)
// result 2022/3/19
console.log(date5)
// result 10:21:30
console.log(date6)
// result Sat, 19 Mar 2022 02:21:30 GMT
</script>
边栏推荐
- 一种跳板机的实现思路
- Threads and thread pools
- What is the best way to learn machine learning
- 【SemiDrive源码分析】【X9芯片启动流程】32 - DisPlay模块分析 - RTOS侧
- Katalon当中的使用循环for、while和if...else、break、continue
- Ribbon core source code analysis
- Ffmpeg audio and video recording
- JS基础4
- [unity][ecs] learning notes (II)
- AGCO AI frontier promotion (6.28)
猜你喜欢

vsftpd服务的部署及优化

【力扣——动态规划】整理题目1:基础题目:509、70、746、62、63、343、96(附链接、题目描述、解题方法及代码)

How does ETF position affect spot gold price?

使用 ABAP 操作 Excel 的几种方法

数据库系列:有什么办法对数据库的业务表进行无缝升级

Sqlcmd database connection error

建立自己的网站(11)
Ribbon核心源码解析
![[unity][ecs] learning notes (I)](/img/eb/1f0ad817bbc441fd8c14d046b82dd0.png)
[unity][ecs] learning notes (I)

Yann Lecun's new paper: the road to building automatic agents
随机推荐
fastposter v2.8.4 发布 电商海报生成器
How to use dataant to monitor Apache apisex
Fabric. How to use js brush?
如何使用 DataAnt 监控 Apache APISIX
树莓派无需显示屏的VNC Viewer方式的远程连接
To enhance the function of jupyter notebook, here are four tips
远程登录sshd服务
Threads and thread pools
建立自己的网站(11)
appliedzkp zkevm(10)中的Transactions Proof
MySQL (II)
Knowing the details of redis RDB, you can step on many holes less
阿里三面:LEFT JOIN关联表中用ON还是WHERE跟条件有什么区别
AQS理解
OpenHarmony应用开发之二维码生成器
关于FTP的协议了解
mysql数据库概述以及安装过程
vsftpd服务的部署及优化
File的io流与base64
Metersphere uses JS to refresh the current page