JavaScript system time setting operation example


This paper illustrates the operation of time setting in JavaScript system. Share for your reference, as follows:

  //myTime typeof //object
  window.onload = function() {
    var obody = document.body;
    // Set up a timer, every second, automatically add a second
    setInterval(fnTime, 1000)
    // If this function is not executed, the first time it is opened, it will take a second to come out.
    function fnTime() {
      var myTime = new Date();
      var iYear = myTime.getFullYear();
      var iMonth = myTime.getMonth() + 1;
      var iDate = myTime.getDate();
      var iWeek = myTime.getDay();
      var iHours = myTime.getHours();
      var iMinutes = myTime.getMinutes();
      var iSeconds = myTime.getSeconds();
      var str = "";
      If (iWeek = 0) iWeek = Sunday
      If (iWeek = 1) iWeek = Monday
      If (iWeek = 2) iWeek = Tuesday
      If (iWeek = 3) iWeek = Wednesday
      If (iWeek = 4) iWeek = Thursday
      If (iWeek = 5) iWeek = Friday
      If (iWeek = 6) iWeek = Saturday
      STR = iYear + year + iMonth + month + iDate + day + iWeek + time + toTwo (iHours) + "time" + toTwo (iMinutes) + "minutes" + toTwo (iSeconds) + "seconds"
      obody.innerHTML = str;
    // The main function of this function is to make: from time to 59 seconds, another second of walking becomes 0, not 00, so we need to change it.
    function toTwo(n) {
       if(n < 10) {
       return "0" + n;
       } else {
       return "" + n;
      // We can use three eyes.
      return n < 10 ? "0" + n : "" + n

Operation results:

Interested friends can use itOnline HTML/CSS/JavaScript Code Running ToolHttp:// tests the performance of the above code.

PS: Here are some time and date related tools for your reference.

Online Date/Date Calculator:

Online Date Calculator/Difference Date Calculator:

Online Date-Date Difference Calculator:

Unix timestamp conversion tool:

Readers who are interested in JavaScript-related content can see the topics on this site: JavaScript Time and Date Operation Skills Summary, JavaScript Search Algorithms Skills Summary, JavaScript Error and Debugging Skills Summary, JavaScript Data Structure and Algorithmic Skills Summary, JavaScript Traversal Algorithms and Skills Summary, and JavaScript Mathematical Operations Usage Summary. Knot

I hope this article will be helpful to the design of JavaScript programs.

Recommended Today

Details of multi-path and large capacity hard disk mount under CentOS

I. application environment and requirementsBlade servers connect HP storage through fiber switches, forming a 2×2 link The storage capacity of the operating system for CentOS 6.4 64 bit mount is 2.5t Based on this application environment, two problems need to be solved: In order to ensure the stability and transmission performance of the link, multi-path […]