HuyPV
Sunday, September 20, 2009
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div id="time" style="">Loading...</div>
<script language="javascript">
function start() {
var q = location.search;
q = q.substring(1);
if(q == '') {
var nY = 1;
if (new Date().getMonth() == 0) nY = 0;
var curYear = new Date().getFullYear();
var defaultYear = curYear + nY;
q = '1/1/' + defaultYear;
}
function parse(q) {
var arr = q.split("/");
var obj = {"ngay":arr[0],"thang":arr[1],"nam":arr[2]};
var d = new Date();
d.setFullYear(obj.nam);
d.setDate(obj.ngay);
d.setMonth(obj.thang - 1);
return d;
}
birthday = parse(q);
birthday.setHours(0);
birthday.setMinutes(0);
birthday.setSeconds(0);
//document.write(birthday);
interval = window.setInterval(
function () {
conphaicho("time");
},
1000
);
}
Date.prototype.format = function(pFormat) {
__d = this.getDate();if (__d < 10) __d = '0' + __d;
__m = this.getMonth() + 1;if (__m < 10) __m = '0' + __m;
__Y = this.getFullYear();
__H = this.getHours(); if (__H < 10) __H = '0' + __H;
__i = this.getMinutes(); if (__i < 10) __i = '0' + __i;
__s = this.getSeconds(); if (__s < 10) __s = '0' + __s;
var specialDay = '';
var formatDate = pFormat.replace(/[dmYHis]/g, function(m, key, value){
//return 'a,' + m + "," + key + ',' + value + '*';
return window['__' + m];
});
if (__d == '01' && __m == '01') specialDay = 'Tết Dương lịch';
return '<span title="' + specialDay + '">' + formatDate + '</span>';
}
function conphaicho(eleId) {
today = new Date( );
if (today.getTime( ) < birthday.getTime( )) {
diff = birthday.getTime() - today.getTime();
document.getElementById(eleId).innerHTML = 'Còn ' + sec2time(diff/1000) + ' là đến ' + birthday.format('H:i:s d-m-Y');
} else {
document.getElementById(eleId).innerHTML = birthday.format('H:i:s d-m-Y') + ' qua mẹ nó rồi còn gì!';
window.clearInterval(interval);
}
}
start();
var delay = function() { conphaicho(eleId); };
function sec2time(sec) {
function time2string(obj) {
var str = '', _0;
if (obj.nam != 0) {
return 'khoảng hơn ' + obj.nam + ' năm';
str = obj.nam + ' năm, ';
}
if (obj.thang != 0) {
str+= obj.thang + ' tháng, ';
}
if (obj.ngay != 0) {
str+= obj.ngay + ' ngày, ';
}
if (obj.gio != 0) {
str+= obj.gio + ' giờ, ';
}
if (obj.phut != 0) {
if (obj.phut < 10) _0 = '0';
else _0 = '';
str+= _0 + obj.phut + ' phút, ';
}
if (obj.giay != -1) {
if (obj.giay < 10) _0 = '0';
else _0 = '';
str+= _0 + obj.giay + ' giây';
}
return str.replace(/, $/, '');
}
var object = {
"nam":0,
"thang":0,
"ngay":0,
"gio":0,
"phut":0,
"giay":0,
}
object.nam = Math.floor(sec / 31536000);
sec = sec % 31536000;
object.thang = Math.floor(sec / 2628000);
sec = sec % 2628000;
object.ngay = Math.floor(sec / 86400);
sec = sec % 86400;
object.gio = Math.floor(sec / 3600);
sec = sec % 3600;
object.phut = Math.floor(sec / 60);
sec = sec % 60;
object.giay = Math.floor(sec);
return time2string(object);
}
</script>
</body>
</html>
Title:
How much days left until specific day
Description:
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <bo...
...
Rating:
4