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>