6 types of JavaScript display current system time code _javascript tips

Source: Internet
Author: User

First: JavaScript displays the current system time code

December 1, 2015 12:05:08 Tuesday

<div id= "JNKC" >

</div>

<script>setinterval ("Jnkc.innerhtml=new Date (). toLocaleString () + ' Week ' + ' Day 123456 '. CharAt (New Date (). Getday ()); ", 1000);

</script>

Second: JavaScript displays the current system time code

December 1, 2015

<script language= "JavaScript" >

<!--

tmpdate = new Date ();

Date = Tmpdate.getdate ();

Month= Tmpdate.getmonth () + 1;

Year= tmpdate.getyear ();

document.write (year);

document.write ("year");

document.write (month);

document.write ("month");

document.write (date);

document.write ("Day");

-->

</script>

Third: JavaScript displays the current system time code

<!--time code start 2015-12-1 Week-->

<script language=javascript>

today=new Date ();

function Initarray () {

this.length=initarray.arguments.length for

(var i=0;i<this.length;i++)

this[ I+1]=initarray.arguments[i]}

var d=new initarray ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");

document.write ("<font color= #0099ff >", Today.getyear (), "Year", Today.getmonth () +1, "Month", Today.getdate (), "Day", d[ Today.getday () +1], "</font>");

</SCRIPT>

<!--time Code end 2015-12-1 Week-->

Fourth (Firefox compatible): JavaScript Displays current system time code

<script language= "JavaScript" type= "Text/javascript" >

<!--

var enabled = 0; today = new Date ();

Var day; var date;

if (Today.getday () ==0) day = ' Sunday '

if (Today.getday () ==1) day = ' Monday '

if (Today.getday () ==2) day = ' Tuesday '

if (to Day.getday () ==3) day = "Wednesday"

if (Today.getday () ==4) day = "Thursday"

if (Today.getday () ==5) day = "Friday"

if (today. Getday () ==6) day = "Saturday"

date = (Today.getfullyear ()) + "year" + (Today.getmonth () + 1) + "month" + today.getdate () + "Days" + Day + "";

document.write (date);

-->

</script>

Fifth: JavaScript Displays the current system time code

<script language= "JavaScript" >

<!--

tmpdate = new Date ();

Date = Tmpdate.getdate ();

Month= Tmpdate.getmonth () + 1;

Year= tmpdate.getyear ();

document.write (year);

document.write ("year");

document.write (month);

document.write ("month");

document.write (date);

document.write ("Day");

-->

</script>

Sixth: JavaScript Displays the current system time code

<script language= "JavaScript" >

var ismonth = new

Array ("January", "February", "March", "April", "May", "June", "July", "August", "September" "," October "," November "," December ");

var isday = new

Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");

Today = new Date ();

Year=today.getyear ();

Date=today.getdate ();

if (document.all)

document.title= "Today is:" +year+ "Year" +ismonth[today.getmonth ()]+date+ "Day" +isday[today.getday ()]

</script>

In IE title bar to display the date time of the JS code

Can let the time, the date displays in your webpage title bar, very individuality function, in fact the code is very simple, saw will, also very good call.

<title> page title bar display time </title>

<script language= "JavaScript" >

var ismonth = new

Array ("January") , "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

var isday = new

Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");

Today = new Date ();

Year=today.getyear ();

Date=today.getdate ();

if (document.all)

document.title= "Today is:" +year+ "Year" +ismonth[today.getmonth ()]+date+ "Day" +isday[today.getday ()]

</script>

The above six kinds of JavaScript show the current system time method, which one favorite method, we can carefully contrast, choose the most suitable one to use.

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.