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

Summary of commonly used SQL statements for creating MySQL tables

Recently, I have been working on a project and ne...

Two ways to enable firewall in Linux service

There are two ways: 1. Service method Check the f...

HTML Language Encyclopedia

123WORDPRESS.COM--HTML超文本标记语言速查手册<!-- --> !D...

Database SQL statement optimization

Why optimize: With the launch of the actual proje...

How to allow remote access to open ports in Linux

1. Modify the firewall configuration file # vi /e...

A brief discussion on Vue3 father-son value transfer

Table of contents From father to son: 1. In the s...

The best 9 foreign free picture material websites

It is difficult to find good image material websi...

13 JavaScript one-liners that will make you look like an expert

Table of contents 1. Get a random Boolean value (...

Detailed examples of Zabbix remote command execution

Table of contents one. environment two. Precautio...

How to uninstall MySQL cleanly (tested and effective)

How to uninstall Mysql perfectly? Follow the step...

How to uninstall Linux's native openjdk and install sun jdk

See: https://www.jb51.net/article/112612.htm Chec...

Docker advanced method of rapid expansion

1. Command method Run the nginx service in the cr...

XHTML Basic 1.1, a mobile web markup language recommended by W3C

W3C recently released two standards, namely "...

Detailed explanation of Nginx process scheduling problem

Nginx uses a fixed number of multi-process models...