[ 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-8x  
Forum » Trao đổi kiến thức lập trình web & chia sẻ code full sạch » Share code tổng hợp full mọi cấu hình web » Code Đếm Ngược Thời Gian Cho Web
Code Đếm Ngược Thời Gian Cho Web
Admin-8x
Data: Thứ ba, 19-01-2016, 3:51 PM
Offline
Bài viết: 21
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.


Star-8x chinh phục mọi thử thách...!
 
Forum » Trao đổi kiến thức lập trình web & chia sẻ code full sạch » Share code tổng hợp full mọi cấu hình web » Code Đếm Ngược Thời Gian Cho Web
  • Page 1 of 1
  • 1
Search:


☠ Home | ✯ Diễn đàn | ✡ Download | ☣ Tin tức | ☢ Video | ☪ Internet | ♘ Game | ✉ Hỗ trợ | ✉ Tin nhắn | Đăng ký | Đăng nhập

BOX ADMIN