当前位置:网站首页>Date object (JS built-in object)
Date object (JS built-in object)
2022-04-23 07:45:00 【Senior salted fish~】
Basic usage :
<script>
// Current time object ( Automatically get the current time of the server )
var date = new Date()
console.log(date)
//UTC 1970.1.1 00:00:00(Date In the object , Save from 1970 year 1 month 1 Japan 00:00:00 The number of milliseconds up to now )
var date1 = new Date(0)
console.log(date1)
//UTC 1970.1.1 00:00:01((1 second =1000 millisecond ))
var date3 = new Date(1000)
console.log(date3)
// Custom time
var date2 = new Date("2022/4/1 12:00:00")
console.log(date2)
// Returns the number of milliseconds (1 second =1000 millisecond )
// obtain 1970 year 01 month 1 Japan 0 The number of milliseconds since zero
console.log(date2.getTime())
// Calculation 5 Minutes later
var date3 = new Date()
// Transformation format (Sat Apr 02 2022 11:26:21 GMT+0800 ( China standard time ))
console.log("5 Minutes later, the time is :" + new Date(date3.getTime() + 5 * 60 * 1000))
// Subtract two times ( Get timestamp ) Returns the number of milliseconds
console.log(date3 - date2)
// Get year
console.log(date.getFullYear() + " year ")
// Get month ( Month from 0 Start )
console.log(date.getMonth() + 1 + " month ")
// Acquisition date
console.log(date.getDate() + " Japan ")
// Get week
console.log(" week " + date.getDay())
// For hours
console.log(date.getHours() + " when ")
// Get minutes
console.log(date.getMinutes() + " branch ")
// Get seconds
console.log(date.getSeconds() + " second ")
// Get local date
console.log(date.toLocaleDateString())
// Get local time
console.log(date.toLocaleTimeString())
// Get local date and time
console.log(date.toLocaleString())
</script>
Print the results 
It is worth noting that the month is from 0 The beginning of the calculation , Don't forget the real month +1!!
版权声明
本文为[Senior salted fish~]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230623087254.html
边栏推荐
猜你喜欢

王者荣耀-unity学习之旅

Super classic & Programming Guide (red and blue book) - Reading Notes

反思 | 事件总线的局限性,组件化开发流程中通信机制的设计与实现

‘npm‘不是内部或外部命令,也不是可运行的程序 或批处理文件

如何SQL 语句UNION实现当一个表中的一列内容为空时则取另一个表的另一列

keytool: command not found

SAP pi / PO rfc2restful publishing RFC interface is a restful example (proxy indirect method)

ogldev-读书笔记

AuthorizationServer(授权服务器的简单搭建)

js之节点操作,为什么要学习节点操作
随机推荐
超级宝典&编程指南(红蓝宝书)-读书笔记
new的实现
4. Multi table query
SAP CR传输请求顺序、依赖检查
数据库查询优化的方式
Understanding of STL container
Use of typescript dictionary
ABAP 7.4 SQL Window Expression
12.约束
Authorization+Token+JWT
13. User and authority management
10.更新操作
js之排他思想及案例
How to judge whether a point is within a polygon (including complex polygons or a large number of polygons)
js之DOM事件
SAP Excel 已完成文件级验证和修复。此工作簿的某些部分可能已被修复或丢弃。
Authorization server (simple construction of authorization server)
BTree、B+Tree和HASH索引
Mobile game performance optimization
FSM finite state machine