当前位置:网站首页>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
边栏推荐
猜你喜欢

BTree、B+Tree和HASH索引

SAP DEBUG调试FOR IN、REDUCE等复杂的语句

redis连接出错 ERR AUTH <password> called without any password configured for the default user.

Solutions to common problems in visualization (VII) solutions to drawing scale setting

Mysql 索引

How to judge whether a point is within a polygon (including complex polygons or a large number of polygons)

Reflect on the limitations of event bus and the design and implementation of communication mechanism in component development process

Authorization+Token+JWT

Discussion on arrow function of ES6

Date对象(js内置对象)
随机推荐
如何SQL 语句UNION实现当一个表中的一列内容为空时则取另一个表的另一列
ABAP 从CDS VIEW 发布OData Service示例
[COCI] Vještica (子集dp)
How to judge whether a point is within a polygon (including complex polygons or a large number of polygons)
js之函数的两种声明方式
配置npm
【TED系列】如何与内心深处的批评家相处?
Authorization+Token+JWT
King glory - unity learning journey
3. Sort statement
VR、AR、MR的区别与应用,以及对AR技术的一些实现原理
js之节点操作,为什么要学习节点操作
Common DOS commands
SAP pi / PO rfc2soap publishes RFC interface as WS example
6. Aggregation function and grouping statistics
Thorough inquiry -- understanding and analysis of cocos2d source code
14.事务处理
SAP CR传输请求顺序、依赖检查
SAP PI/PO rfc2RESTful 发布rfc接口为RESTful示例(Proxy间接法)
页面动态显示时间(升级版)