当前位置:网站首页>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>
边栏推荐
- [oauth2] VIII. Configuration logic of oauth2 login -oauth2loginconfigurer and oauth2clientconfigurer
- 【开源之美】nanomsg(2) :req/rep 模式
- 我们被一个 kong 的性能 bug 折腾了一个通宵
- 重押海外:阿里、京东、顺丰再拼“内力”
- The last time I heard about eBay, or the last time
- 多线程使用不当导致的 OOM
- [shaders realize overlay to re cover cross dressing effect _shader effect Chapter 9]
- [dark horse morning post] many apps under bytek have been taken off the shelves; The leakage of deoxidizer in three squirrels caused pregnant women to eat by mistake; CBA claimed 406million yuan from
- Tupu 3D visual national style design | collision between technology and culture "cool" spark“
- Force deduction ----- the number of words in the string
猜你喜欢
Exploration on cache design optimization of community like business

【OAuth2】八、OAuth2登录的配置逻辑-OAuth2LoginConfigurer和OAuth2ClientConfigurer

Jenkins 中 shell 脚本执行失败却不自行退出

Implementation of SAP ABAP daemon

One stroke problem (Chinese postman problem)

Can I take your subdomain? Exploring Same-Site Attacks in the Modern Web

上一次听到易趣,还是上一次

Basic sentence structure of English ----- origin
![[oauth2] VIII. Configuration logic of oauth2 login -oauth2loginconfigurer and oauth2clientconfigurer](/img/7e/4f652c4d3d72ad563ddbc1c1f1f50b.png)
[oauth2] VIII. Configuration logic of oauth2 login -oauth2loginconfigurer and oauth2clientconfigurer

Frisbee, 2022 "black red" top stream
随机推荐
Jenkins 中 shell 脚本执行失败却不自行退出
LeetCode 69. x 的平方根
flutter多渠道打包运行
MySQL data directory (1) -- database structure (24)
Solve the problem that the remote host cannot connect to the MySQL database
Some practical operations of vector
[flower carving hands-on] fun music visualization series small project (12) -- meter tube fast rhythm light
Click El dropdown item/@click.native
Tdsql-c serverless: help start-ups achieve cost reduction and efficiency increase
算法--连续数列(Kotlin)
Golang端口扫描设计
[oauth2] VII. Wechat oauth2 authorized login
Time complexity and space complexity
历时15年、拥有5亿用户的飞信,彻底死了
With 8 years of product experience, I have summarized these practical experience of continuous and efficient research and development
LCL three-phase PWM rectifier (inverter)
B+ tree index use (6) leftmost principle -- MySQL from entry to proficiency (18)
Tupu 3D visual national style design | collision between technology and culture "cool" spark“
Probability theory and mathematical statistics
Sword finger offer (x): rectangular coverage