当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
9. Common functions
SAP PI/PO rfc2RESTful 發布rfc接口為RESTful示例(Proxy間接法)
Design optimization of MySQL database
FSM finite state machine
对js中argumens的简单理解
11. Table and library management
js案例之求最大值,反转数组,冒泡排序
SAP SALV14 后台输出SALV数据可直接保存文件,发送Email(带排序、超链接、筛选格式)
数据库查询优化的方式
SAP Excel 已完成文件级验证和修复。此工作簿的某些部分可能已被修复或丢弃。
【TED系列】一个习惯是如何改变我的一生
[Ted series] how does a habit change my life
Learn to use search engines
SAP DEBUG调试FOR IN、REDUCE等复杂的语句
FSM有限状态机
keytool: command not found
[Educational Codeforces Round 80] 解题报告
刨根问底---cocos2d源码的理解与分析
Mobile game performance optimization
超级宝典&编程指南(红蓝宝书)-读书笔记