Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 973173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:14:22+00:00 2026-05-16T03:14:22+00:00

I have a timer that runs on the website. It will retrieve a timespan

  • 0

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?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T03:14:23+00:00Added an answer on May 16, 2026 at 3:14 am

    One error I can see is that you shouldn’t be subtracting one here:

    TimeRemaining.TotalMinutes - 1
    

    If there is less than thirty seconds remaining and you subtract one minute you will get a negative number.

    TimeSpan timeRemaining = TimeSpan.FromSeconds(25);
    string s = (timeRemaining.TotalMinutes - 1).ToString("N0");
    Console.WriteLine(s);
    

    Result:

    -1
    

    Instead you should round this number down to an integer (also called truncation). You can do this with Math.Floor, but it is also possible to just cast the number to an integer to achieve the same effect:

    (int)TimeRemaining.TotalMinutes
    

    As for the seconds, I don’t know why that is going wrong. I assume it is because your time remaining can in fact go negative. The error seems to not be in the code you posted.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some javascript which runs a timer that animates something on the website.
I have a repeating timer that runs down a clock. During the clock running
I have a aspx page that has a UpdatePanel and a asp timer. the
My website has a search procedure that runs very slowly. One thing that slows
I have a process that runs long, and I want to update a label
My website is a community; we have forums and user profiles, and everyone has
I have a cron entry that runs a script at a certain time each
I have a timer that needs to not process its elapsed event handler at
I have a timer that ticks every 3 seconds. If the timer found something
I have a timer tick that I would like to kick off my backgroundworker

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.