当前位置:网站首页>JS get the current time, time and timestamp conversion
JS get the current time, time and timestamp conversion
2022-07-26 13:41:00 【Tangce】
One 、 attribute
11.6 Get the current time , count down
js Get time from new date() Usage of
var myDate = new Date();// Get the current time of the system
myDate.getYear(); // Get current year (2 position )
myDate.getFullYear(); // Get full year (4 position ,1970-???)
myDate.getMonth(); // Get current month (0-11,0 representative 1 month )
myDate.getDate(); // Get current day (1-31)
myDate.getDay(); // Get current week X(0-6,0 For Sunday )
myDate.getTime(); // Get the current time ( from 1970.1.1 Milliseconds to start )
myDate.getHours(); // Get current hours (0-23)
myDate.getMinutes(); // Get current minutes (0-59)
myDate.getSeconds(); // Get current seconds (0-59)
myDate.getMilliseconds(); // Get current milliseconds (0-999)
myDate.toLocaleDateString(); // Get current date
var mytime=myDate.toLocaleTimeString(); // Get the current time
myDate.toLocaleString( ); // Get date and time
Two 、 Example
Eg:
One : Time to time stamp :javascript There are four ways to get a timestamp , All by instantiating time objects new Date() To further obtain the current timestamp
1.var timestamp1 = Date.parse(new Date()); // result :1477808630000 This method is not recommended , Millisecond level values are converted to 000
console.log(timestamp1);
2.var timestamp2 = (new Date()).valueOf(); // result :1477808630404 adopt valueOf() Function returns the original value of the specified object to get the exact timestamp value
console.log(timestamp2);
3.var timestamp3 = new Date().getTime(); // result :1477808630404 , Get the millisecond value of the current time directly through the prototype method , accuracy
console.log(timestamp3);
4.var timetamp4 = Number(new Date()) ; // result :1477808630404 , Turn time into a number Type value , Timestamp
console.log(timetamp4);
3、 ... and 、demo
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title> Easy to use countdown js Code - Stationmaster material </title>
<style>
*{ margin:0; padding:0; list-style:none;}
body{ font-size:18px; text-align:center;}
.time{ height:30px; padding:200px;}
</style>
</head>
<body>
<div class="time">
<span id="t_d">00 God </span>
<span id="t_h">00 when </span>
<span id="t_m">00 branch </span>
<span id="t_s">00 second </span>
</div>
<script>
function GetRTime(){
// Double 11 countdown draw
var EndTime= new Date('2018/11/11 00:00:00');
var NowTime = new Date();
var t =EndTime.getTime() - NowTime.getTime();
var d=Math.floor(t/1000/60/60/24);
var h=Math.floor(t/1000/60/60%24);
var m=Math.floor(t/1000/60%60);
var s=Math.floor(t/1000%60);
document.getElementById("t_d").innerHTML = d + " God ";
document.getElementById("t_h").innerHTML = h + " when ";
document.getElementById("t_m").innerHTML = m + " branch ";
document.getElementById("t_s").innerHTML = s + " second ";
}
setInterval(GetRTime,0);
</script>
</body>
</html>
边栏推荐
- MySQL data directory (1) -- database structure (24)
- 详解关系抽取模型 CasRel
- [oauth2] VIII. Configuration logic of oauth2 login -oauth2loginconfigurer and oauth2clientconfigurer
- Force deduction ----- the number of words in the string
- Activity.onStop() 延迟10秒?精彩绝伦的排查历程
- .net6与英雄联盟邂逅之——根据官方LCU API制作游戏助手
- B+ tree (4) joint index -- MySQL from entry to proficiency (16)
- LeetCode 217. 存在重复元素
- One stroke problem (Chinese postman problem)
- The.Net webapi uses groupname to group controllers to render the swagger UI
猜你喜欢

Why does WPS refuse advertising?

《Kotlin系列》之MVVM架构封装(kotlin+mvvm)

Hcip day 12 notes sorting (BGP Federation, routing rules)
![[oauth2] VII. Wechat oauth2 authorized login](/img/1a/3f2b9fc57759a1fa3fda1451492e5c.png)
[oauth2] VII. Wechat oauth2 authorized login

Target detection network r-cnn series

Probability theory and mathematical statistics

Implementation of SAP ABAP daemon

【Oauth2】五、OAuth2LoginAuthenticationFilter

Basic sentence structure of English ----- origin

AI theory knowledge map 1 Foundation
随机推荐
LCL三相pwm整流器(逆变器)
Leetcode 2119. number reversed twice
飞盘,2022年“黑红”顶流
向路由组件传递参数
HCIP第十一天比较(BGP的配置、发布)
Brief introduction of reflection mechanism
Dimension disaster dimension disaster suspense
Pytorch学习笔记(二)神经网络的使用
时间复杂度和空间复杂度
【Oauth2】五、OAuth2LoginAuthenticationFilter
Click El dropdown item/@click.native
JSON data transfer parameters & date type parameter transfer
The last time I heard about eBay, or the last time
周伟:寻找非共识性投资机会,陪伴延迟满足的创始团队
flutter多渠道打包运行
Basic sentence structure of English ----- origin
LeetCode 263.丑数
B+ tree selection index (1) -- MySQL from entry to proficiency (22)
Tianjin emergency response Bureau and central enterprises in Tianjin signed an agreement to deepen the construction of emergency linkage mechanism
Jenkins 中 shell 脚本执行失败却不自行退出