Home > Web Front-end > JS Tutorial > JavaScript method to display the current date and time on the browser title bar_javascript tips

JavaScript method to display the current date and time on the browser title bar_javascript tips

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 16:08:21
Original
1510 people have browsed it

The example in this article describes how JavaScript displays the current date and time on the browser title bar. I would like to share it with you for your reference. The details are as follows:

Put this script into the head area:

<script language="JavaScript">
<!--
function resetIt() {
// Calculate Time
var timerID = null;
var timerRunning = false;
if(timerRunning)
  clearTimeout(timerID);
  timerRunning = false;
// getTime
var timeNow = new Date();
var hours = timeNow.getHours();
var minutes = timeNow.getMinutes();
var seconds = timeNow.getSeconds();
var timeValue = "" + ((hours >12) &#63; hours -12 :hours)
timeValue = ((timeValue <10)&#63; "0":"") + timeValue
timeValue += ((minutes < 10) &#63; ":0" : ":") + minutes
timeValue += ((seconds < 10) &#63; ":0" : ":") + seconds
timeValue += (hours >= 12) &#63; " PM" : " AM"
timerID = setTimeout("resetIt()",100);
timerRunning = true;
// getDate
var dateNow = new Date();
var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
var date = ((dateNow.getDate()<10) &#63; "0" : "")+ dateNow.getDate();
function y2k(number){return (number < 1000) &#63; number + 1900 : number;}
// compileIt
today = timeValue + " " + days[dateNow.getDay()] + " " +
        months[dateNow.getMonth()] + ", " +
        date + " " +
        (y2k(dateNow.getYear()));
  if(document.all || document.getElementById){ // Browser Check
   document.title = today.toString();
  }else{
   self.status = today.toString(); // Default to status.
  }
}
resetIt();
//-->
</script>
Copy after login

I hope this article will be helpful to everyone’s JavaScript programming design.

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template