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 7591387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:38:20+00:00 2026-05-30T20:38:20+00:00

I want to display duration with milliseconds on a web page. So far I

  • 0

I want to display duration with milliseconds on a web page. So far I have done this:
I managed to display this output on a label: 00:02:50, but I want to display milliseconds as well, so the result should look like this 00:02:50:000. How do I achieve this?

Code behind:

protected void Page_Load(object sender, EventArgs e)
{
    DateTime startTime = DateTime.Now;
    // sleep for 2.5s
    Thread.Sleep(2500);
    DateTime stopTime = DateTime.Now;
    TimeSpan duration = stopTime - startTime;
    Result.Text = duration.ToString("mm':'ss':'ff");
}
  • 1 1 Answer
  • 0 Views
  • 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-30T20:38:22+00:00Added an answer on May 30, 2026 at 8:38 pm

    First of all, if you’re timing things I would recommend using the StopWatch class as that’s what it’s there for. You can find it in the System.Diagnostics namespace: System.Diagnostics.Stopwatch.

    You can instantiate a new one and start measuring the elapsed amount of time with one line of code: var stop = System.Diagnostics.Stopwatch.StartNew(); and then stop the timer with the stop method: stop.Stop();. You can then return the elapsed time using the Elapsed property var elapsed = stop.Elapsed;.

    Then in order to display the elapsed time with milliseconds you would call the ToString method on the elapsed timespan with the correct parameters.

    So putting it all together your code would look like this:

    protected void Page_Load(object sender, EventArgs e)
    {
        var timer = System.Diagnostics.Stopwatch.StartNew();
        // sleep for 2.5s
        Thread.Sleep(2500);
        timer.Stop();
        var elapsed = timer.Elapsed;
        Result.Text = elapsed.ToString("mm':'ss':'fff");
    }
    

    Hope that helps!

    James

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

Sidebar

Related Questions

I have db with this table (TableToDo): http://goo.gl/NlTEk I want display all records in
I want to display result of this javascript in a label control on my
I have this div I want to hide ( display:none ) after it fades
I have a simple quiz application and I want display a nice timer /
In the header of the django admin, I want display a link. This link
I want to display visual/auditory stimuli inside a web browser for psychophysic experiments. I
I want to display jquery notifications, but at the moment it is fired onclick.
i want my c# program to be able to display the online duration of
I have this code below and want it to show the progress of a
Hi I want to display player position and player duration in simple date format.

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.