I have a timer that runs on the website. It will retrieve a timespan of how long a user has until their order expires. For the most part this works fine, the server will return the initial time remaining and the javascript will do the countdown. So it displays
2:30
2:29
2:28
Then for some reason, on some of the page loads (seems to happen when the timer has less than 60 seconds remaining), the formatting turns to
-1:0-45
-1:0-46
-1:0-47
This is the code responsible for formatting the timespan:
<%= (TimeRemaining.TotalMinutes - 1).ToString("N0") %>:<%= TimeRemaining.Seconds.ToString("N0").PadLeft(2,'0') %>
I've also just tried the following with the same result.
<%= String.Format("{0:0}:{1:00}", TimeRemaining.TotalMinutes-1, TimeRemaining.Seconds)%>
I also have a check on the TimeRemaining, if the TotalSeconds is <= 0, then it just returns a new TimeSpan(0)
, so it should never be going negative. It's not the javascript thats screwing up the countdown, because I can disable it and still see the messed up formatted time.
Is there a better/cleaner way to do this?