开发者

javascript time ticker

开发者 https://www.devze.com 2023-04-06 22:30 出处:网络
I want to build a simple time ticker. Basically I will have a global javascript variable injected from the server side that will represent in my business model a active task start time for an agent.

I want to build a simple time ticker.

Basically I will have a global javascript variable injected from the server side that will represent in my business model a active task start time for an agent.

I want to show in a tag the digital time format between that 开发者_如何学JAVAglobal that date and now, but the issue I have is with the milliseconds from the difference between those 2 dates.

I have created a JSFiddle but the difference between new Date() and that specific date is not showing properly.

enter code herehttp://jsfiddle.net/alexpeta/ZmzDh/3/

Can you guys spot the bug or the issue?


d.toLocaleString() might have a word with you ;) tip: no, you are not measuring time since September 22, you are measuring time to October 22.

http://jsfiddle.net/LDKh7/


Example

Replace:

var t = setInterval('tick()',1000);

with:

var t = setInterval(tick,1000);

It's always a good idea to use function reference and not a string in setInterval


 <script language="JavaScript">
  TargetDate = "12/31/2020 5:00 AM";
  BackColor = "palegreen";                   
  ForeColor = "navy";                    
  CountActive = true;                   
  CountStepper = -1;                 
  LeadingZero = true;                            
  DisplayFormat = "%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%%   Seconds.";                      
  FinishMessage = "It is finally here!";                  
   </script>
  <script language="JavaScript" src="http://scripts.hashemian.com/js/countdown.js"></script>  
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号