JS Get current date

Source: Internet
Author: User

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> Untitled Document </title>
<script type= "Text/javascript" >
function Curtime () {
var now = new Date ();
var year = Now getFullYear ();
Var month =add_zero (now. GetMonth () +1);
Var day =add_zero (now GetDate ());
var dy = now getDay ();//Get Week
Day of the week formatting
VAR week;
Switch (DY) {
Case 1:week= "Monday"; Break
Case 2:week= "Tuesday"; Break
Case 3:week= "Wednesday"; Break
Case 4:week= "Thursday"; Break
Case 5:week= "Friday"; Break
Case 6:week= "Saturday"; Break
default:week= "Sunday";
}
var hour = Add_zero (now. getHours ());
var minute = Add_zero (now. getminutes ());
var second = Add_zero (now. getseconds ());
var time=year+ "Year" +month+ "month" +day+ "Day" + "&nbsp;&nbsp;&nbsp;" +week+ "&nbsp;&nbsp;&nbsp;" +hour+ ":" +minute+ ":" +second;
document.getElementById ("Curtime"). Innerhtml=time;
}
Add 0 to the number before 10
function Add_zero (temp)
{
if (temp<10) return "0" +TEMP;
else return temp;
}
Add a timer to execute the Curtime () function once per second
SetInterval ("Curtime ()", 1000);
</script>

<body>
<div id= "Curtime" ></div>
</body>



Display effect:

August 17, 2015 Monday 11:38:45

JS Get current date

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.