JS time and date countdown and moving time code

Source: Internet
Author: User
Tags local time setinterval time and date

JS time and date countdown and moving time code

<script type= "text/web Effects" >
Window.onload = function () {
StartTime ();
}
function StartTime () {
try{
var today = new Date ();
var year = Today.getfullyear ();
var month = Checknum (Today.getmonth () +1);
var date = Checknum (Today.getdate ());
var day = Today.getday ();
var hour = Checknum (Today.gethours ());
var minute = Checknum (Today.getminutes ());
var second = Checknum (Today.getseconds ());
Switch (day) {
Case 1:
Day = "one";
Break
Case 2:
Day = "Two";
Break
Case 3:
Day = "three";
Break
Case 4:
Day = "Four";
Break
Case 5:
Day = "Five";
Break
Case 6:
Day = "Six";
Break
Case 7:
Day = "th";
Break
}
var fulltime = year+ "year" +month+ "month" +date+ "Day" + "Week" +day+ "" +hour+ ":" +minute+ ":" +second;
document.getElementById ("Showtime"). innerHTML = fulltime;
SetInterval (' StartTime () ', 1000);
}
catch (e) {
alert (e.description);
}
}
function Checknum (num) {
if (num<10) {
num = "0" +num;
}
return num;
}
</script>
<div id= "Showtime" ></div>

Countdown

<script type= "Text/javascript" >
function Countdown (EndDate) {
var now = new Date ();
var deadtime = document.getElementById (EndDate);
var deadline = new Date (deadtime.value);
Minute difference between local time and Greenwich Mean Time (GMT)
var Timediff = Now.gettimezoneoffset ();
There is some confusion here, if the minute difference into milliseconds should be timediff*60*1000, but this return of the data is not correct!
var leave = Math.Abs (Deadline.gettime ()-now.gettime () + timediff*60);
var minute = 1000 * 60;
var hour = minute * 60;
var day = hour * 24;
var countday = Math.floor (Leave/day);
var counthour = Math.floor ((leave-day*countday)/hour); Two kinds of calculation ideas
var counthour = Math.floor (leave/hour-countday*24);
var countminute = Math.floor (leave/minute)-countday*24*60-counthour*60;
var countsecond = Math.floor (leave/1000)-countday*24*60*60-counthour*60*60-countminute*60;
var outstr = "";
if (Deadline < now) {
outstr = "Distance" +deadtime.value+ "+countday+" "Days" +counthour+ "hours" +countminute+ "minutes" +countsecond+ "seconds";
} else {
outstr = "Distance" +deadtime.value+ "still Poor" +countday+ "Days" +counthour+ "hours" +countminute+ "minutes" +countsecond+ "seconds";
}
var showtime = document.getElementById ("Showtime");
showtime.innerhtml = outstr;
}
</script>
<body>
<p>
<label for= "Deadline" > Due date </label>
<input type= "text" value= "2011-06-11" id= "Deadline"/>
<input type= "button" value= "Start Countdown" onclick= "Window.setinterval (' Countdown ')" Deadline "1000"
</p>
<p id= "Showtime" ></p>

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.