当前位置:网站首页>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>
边栏推荐
- 【功能建议】多个工作空间启动时选择某个空间
- Sqlcmd database connection error
- June training (day 28) - Dynamic Planning
- Fastposter v2.8.4 release e-commerce poster generator
- 【实战】1364- 实现一个完美的移动端瀑布流组件(附源码)
- Ruoyi integrated building block report (NICE)
- DlhSoft Kanban Library for WPF
- [unity][ecs] learning notes (III)
- ruoyi集成积木报表(nice)
- Katalon当中的debug调试
猜你喜欢

AGCO AI frontier promotion (6.28)

Katalon当中的debug调试

【实战】1364- 实现一个完美的移动端瀑布流组件(附源码)

Sqlcmd database connection error

Metersphere实现UI自动化元素不可点击(部分遮挡)

Information hidden in the trend chart of Hong Kong London gold market

Interface automation framework scaffold - use reflection mechanism to realize the unified initiator of the interface

To enhance the function of jupyter notebook, here are four tips

How does ETF position affect spot gold price?

线程和线程池
随机推荐
DlhSoft Kanban Library for WPF
Information hidden in the trend chart of Hong Kong London gold market
Redis database
To enhance the function of jupyter notebook, here are four tips
壓縮解壓
How to use dataant to monitor Apache apisex
[Agora] get an Agora_ Example usage of refptr object
[monkey] Introduction to monkey test
Summary of spatial temporal time series prediction modeling methods
What is the best way to learn machine learning
MySQL查看数据库性能常用命令
AQS understanding
AQS理解
Katalon当中的output使用方法
广州海关支持保障食品、农产品和中药材等民生物资稳定供港
Dataease installation upgrade
Compression and decompression
OpenHarmony应用开发之二维码生成器
Guangzhou Customs supports the stable supply of food, agricultural products, traditional Chinese medicine and other civilian and biological resources to Hong Kong
Mongo database