[ Tin nhắn mới · Thành viên · Nội quy diễn đàn · Tìm kiếm · RSS ]
  • Page 1 of 1
  • 1
Forum moderator: Admin, Administrators  
Diễn đàn » Trao đổi kiến thức thiết kế web, lập trình code ... » Chia sẻ code web full sạch đẹp cho các member » Code đếm ngược thời gian cho web (đếm ngược thời gian web chạy)
Code đếm ngược thời gian cho web
Yasuo
Data: Thứ hai, 2015-12-21, 3:47 PM
Offline
Bài viết: 24
Rất tiện dụng dành cho những trang mua hàng có giới hạn thời gian mua sắm

Code
<script type="text/javascript">
var year=2014;//năm
var month=5;//tháng
var day=15;//ngày
var h=12;//giờ
var i=0;//phút
var s=0;//giây
dateFuture1 = new Date(year,month,day,h,i,s);
function GetCount(ddate,iid){

dateNow = new Date(); //grab current date
amount = ddate.getTime() - dateNow.getTime(); //calc milliseconds between dates
delete dateNow;

// if time is already past
if(amount < 0){
document.getElementById(iid).innerHTML="Now!";
}
// else date is still good
else{
days=0;hours=0;mins=0;secs=0;out="";

amount = Math.floor(amount/1000);//kill the "milliseconds" so just secs

days=Math.floor(amount/86400);//days
amount=amount%86400;

hours=Math.floor(amount/3600);//hours
amount=amount%3600;

mins=Math.floor(amount/60);//minutes
amount=amount%60;

secs=Math.floor(amount);//seconds
out += (days<=9?'0':'')+days +" "+((days==1)?"Ngày":"Ngày")+", ";
out += (hours<=9?'0':'')+hours +" "+((hours==1)?"hour":"Giờ")+", ";
out += (mins<=9?'0':'')+mins +" "+((mins==1)?"min":"Phút")+", ";
out += (secs<=9?'0':'')+secs +" "+((secs==1)?"sec":"Giây")+", ";
out = out.substr(0,out.length-2);
document.getElementById(iid).innerHTML=out;

setTimeout(function(){GetCount(ddate,iid)}, 1000);
}
}

window.onload=function(){
GetCount(dateFuture1, 'countbox1');
//you can add additional countdowns here (just make sure you create dateFuture2 and countbox2 etc for each)
};
</script>
<div id="countbox1"></div>


Chú ý:
- Tháng phải trừ đi 1

Ví dụ:
- Ngày bạn kết thúc: 12:00:00 14-6-2014
- Thì chuyển thành: 12:00:00 14-5-2014

Bạn chỉnh sửa lại thông tin cho phù hợp:
var year=2014;//năm
var month=5;//tháng
var day=15;//ngày
var h=12;//giờ
var i=0;//phút
var s=0;//giây


Thời gian bắt đầu là thời gian mặc định trên máy của khách hàng

Từ khóa tìm kiếm:

Xin code dem nguoc thoi gian cho web, huong dan tao code dam nguoc thoi gian web ban hang, cach lam code dem ngươc thoi gian cho web dep, code full dep cho web, tuyen chon code hay cho web, code moi nhat sach se nhat, nhung coe huu ich khi lap trinh web, code can thiet khi lam trinh web.
 
Diễn đàn » Trao đổi kiến thức thiết kế web, lập trình code ... » Chia sẻ code web full sạch đẹp cho các member » Code đếm ngược thời gian cho web (đếm ngược thời gian web chạy)
  • Page 1 of 1
  • 1
Search:


☠ Home | ✯ Diễn đàn | ✡ Download | ☣ Nấu ăn | ☢ Video | ☪ Truyện cười | ♘ Mẹo vặt | ✉ Hỗ trợ | ✉ Tin nhắn | Đăng ký | Đăng nhập

BOX ADMIN