How does JavaScript display the current date and time on the browser title bar?

Source: Internet
Author: User

How does JavaScript display the current date and time on the browser title bar?

This article mainly introduces how to display the current date and time in the title bar of the browser by using JavaScript. The example analyzes the javascript operation time and DOM node implementation timing triggering techniques, which is of great practical value, for more information, see

 

 

This article describes how to display the current date and time in the title bar of the browser by using JavaScript. The details are as follows:

Put this script in the head area:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

<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 )? Hours-12: hours)

TimeValue = (timeValue <10 )? "0": "") + timeValue

TimeValue + = (minutes <10 )? ": 0": ":") + minutes

TimeValue + = (seconds <10 )? ": 0": ":") + seconds

TimeValue + = (hours> = 12 )? "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', 'marril', 'may', 'june', 'july', 'August ', 'September ', 'October', 'november', 'december ');

Var date = (dateNow. getDate () <10 )? "0": "") + dateNow. getDate ();

Function y2k (number) {return (number <1000 )? 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>

I hope this article will help you design javascript programs.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.