JS Buy Countdown

Source: Internet
Author: User
Tags time zones local time

The client code can look at:

Http://www.zhangxinxu.com/wordpress/2010/07/%E5%9B%A2%E8%B4%AD%E7%B1%BB%E7%BD%91%E7%AB%99%E5%80%92%E8%AE%A1%E6 %97%b6%e7%9a%84js%e5%ae%9e%e7%8e%b0/

/*by Zhangxinxu 2010-07-27 * http://www.zhangxinxu.com/* Countdown implementation*/varFntimecountdown =function(d, O) {varf ={zero:function(n) {varn = parseint (n, 10); if(N > 0){                if(N <= 9) {n= "0" +N; }                returnString (n); }Else{                return"00"; }}, DV:function() {D= d | | DATE.UTC (2050, 0, 1);//If no time is defined, we set the countdown date to January 1, 2050            varFuture =NewDate (d), now =NewDate (); //now future seconds Difference            varDur = Math.Round ((Future.gettime ()-now.gettime ())/+ Future.gettimezoneoffset () *, PMS ={sec:"00", Mini:"00", hour:"00", Day:"00", Month:"00", Year:"0"            }; if(Dur > 0) {pms.sec= F.zero (dur% 60); Pms.mini= Math.floor ((dur/60)) > 0? F.zero (Math.floor ((DUR/60))% 60): "00"; Pms.hour= Math.floor ((dur/3600)) > 0? F.zero (Math.floor ((dur/3600))% 24): "00"; Pms.day= Math.floor ((dur/86400)) > 0? F.zero (Math.floor ((dur/86400))% 30): "00"; //month, calculated as the actual average number of seconds per monthPms.month = Math.floor ((dur/2629744)) > 0? F.zero (Math.floor ((dur/2629744))% 12): "00"; //year, press the regression year 365 days 5:48 46 second CountPms.year = Math.floor ((dur/31556926)) > 0? Math.floor ((dur/31556926)): "0"; }            returnPMS; }, UI:function(){            if(o.sec) {o.sec.innerhtml=F.dv (). sec; }            if(O.mini) {o.mini.innerhtml=F.DV (). Mini; }            if(o.hour) {o.hour.innerhtml=F.DV (). hour; }            if(o.day) {o.day.innerhtml=F.DV (). Day; }            if(o.month) {o.month.innerhtml=F.DV (). Month; }            if(o.year) {o.year.innerhtml=F.DV (). Year; } setTimeout (F.ui,1000);        }    }; F.ui ();};

Attention:

getTimezoneOffset (), which returns the time difference between GMT and local times, is a single digit in minutes . To get the seconds *60.

The getTimezoneOffset () method returns the number of minutes between the local time and the GMT or UTC time. In effect, the function tells us the time zone where the JavaScript code is running and whether the specified time is daylight saving.

Returns are measured in minutes, not hours, because some countries have time zones that are even less than one hours apart.

Beijing shows:

D.gettimezoneoffset ()-480an article:Recently done a real estate of the second kill, group buying e-commerce site (the house also has a second kill, shot not small AH), which has a seconds to kill the countdown display, mainly to determine the current time distance seconds to kill the beginning of how much time, there are seconds to kill the start and kill the end of various displays. The main point is that the so-called current time can not use the browser through the new Date () to obtain the client time, so long as the user modifies their own machine time so the countdown will be chaotic, so this current time must use the server time, So using a static cache page so this current time using Ajax method for reference: http://www.blogjava.net/dongbule/archive/2012/01/10/368229.html

JS Buy Countdown

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.