js implements a simple countdown

js implements a simple countdown

This article example shares the specific code of js to implement a simple countdown for your reference. The specific content is as follows

Code:

<!DOCTYPE html>
<html lang="en">
 
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="./3. Fill zero when less than 10.js"></script>
  <style>
    div {
      float: left;
      width: 100px;
      height: 100px;
      background-color: #000;
      text-align: center;
      line-height: 100px;
      color: #fff;
      font-size: 30px;
      margin-right: 10px;
    }
  </style>
</head>
 
<body>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <script>
    var div = document.getElementsByTagName('div');
    var inputTime = +new Date('2021-02-05 00:00:00'); //The total number of milliseconds from the user input time to January 1, 1970 setInterval(countTime, 1000);
    countTime();
 
    function countTime() {
      var nowTime = +new Date(); //Total number of milliseconds from the current time to January 1, 1970 // console.log(timer);
      var times = (inputTime - nowTime) / 1000; // seconds var d = parseInt(times / 60 / 60 / 24); // days div[0].innerHTML = addZero(d) + 'days';
      var h = parseInt(times / 60 / 60 % 24) //div[1].innerHTML = addZero(h) + 'time';
      var m = parseInt(times / 60 % 60); //div[2].innerHTML = addZero(m) + '分';
      var s = parseInt(times % 60); //seconds div[3].innerHTML = addZero(s) + 'seconds';
 
 
    }
  </script>
</body>
 
</html>

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • JS countdown implementation code (hours, minutes, seconds)
  • JS countdown (days, hours, minutes, seconds)
  • Simple and easy to use countdown js code
  • js code to realize the 60-second countdown when clicking the button
  • 2 simple js countdown methods
  • Example of implementing a simple countdown function using native JS
  • js countdown jump example after a few seconds
  • A good js html page countdown can be accurate to seconds
  • js realizes the countdown effect of clicking to get the verification code
  • Javascript implements the countdown for product flash sales (time is synchronized with server time)

<<:  mysql 5.7.11 winx64.zip installation and configuration method graphic tutorial

>>:  Detailed explanation of Linux server status and performance related commands

Recommend

Two simple menu navigation bar examples

Menu bar example 1: Copy code The code is as foll...

10 excellent Web UI libraries/frameworks

1. IT Mill Toolkit IT Mill Toolkit is an open sou...

Pay attention to the use of HTML tags in web page creation

This article introduces some issues about HTML ta...

How to use JavaScript and CSS correctly in XHTML documents

In more and more websites, the use of XHTML is rep...

js to achieve the pop-up effect

This article example shares the specific code of ...

Pure CSS to achieve left and right drag to change the layout size

Utilize the browser's non- overflow:auto elem...

Detailed explanation of the solution to the nginx panic problem

Regarding the nginx panic problem, we first need ...

12 Useful Array Tricks in JavaScript

Table of contents Array deduplication 1. from() s...

CentOS7 uses rpm package to install mysql 5.7.18

illustrate This article was written on 2017-05-20...

When modifying a record in MySQL, the update operation field = field + string

In some scenarios, we need to modify our varchar ...

How to quickly use mysqlreplicate to build MySQL master-slave

Introduction The mysql-utilities toolset is a col...

Detailed explanation of writing multiple conditions of CSS: not

The :not pseudo-class selector can filter element...

Linux automatically deletes logs and example commands from n days ago

1. Delete file command: find the corresponding di...

Some common mistakes with MySQL null

According to null-values, the value of null in My...