Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Need to display the resultant time in hours:min:sec format.

Need to display the resultant time in hours:min:sec format.

Scheduled Pinned Locked Moved ASP.NET
tutorial
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Satish Developer
    wrote on last edited by
    #1

    Hi, i need to display the times on my webpage. They are start time, end time and the reultant time. i wrote the following code. TimeSpan _starttime = DateTime.Now.TimeOfDay; TimeSpan _endtime = DateTime.Now.TimeOfDay; TimeSpan _finaltime = _endtime.Subtract(_starttime); Response.write("Start Time: " + _starttime + "-- End Time: " + _endtime + "-- Finaltime:" + _finaltime); i am getting result as 02:45:27.9085452-- End Time: 02:52:59.2926579-- Finaltime:00:07:31.3841127 Here i am getting milliseconds...how to avoid this in displaying. i want to display time as 02:45:27

    G. Satish

    N S K 3 Replies Last reply
    0
    • S Satish Developer

      Hi, i need to display the times on my webpage. They are start time, end time and the reultant time. i wrote the following code. TimeSpan _starttime = DateTime.Now.TimeOfDay; TimeSpan _endtime = DateTime.Now.TimeOfDay; TimeSpan _finaltime = _endtime.Subtract(_starttime); Response.write("Start Time: " + _starttime + "-- End Time: " + _endtime + "-- Finaltime:" + _finaltime); i am getting result as 02:45:27.9085452-- End Time: 02:52:59.2926579-- Finaltime:00:07:31.3841127 Here i am getting milliseconds...how to avoid this in displaying. i want to display time as 02:45:27

      G. Satish

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      Use ToString[^]. See the different pattern ToString takes. Alternatively, you can use StopWatch[^] class. :)

      Navaneeth How to use google | Ask smart questions

      1 Reply Last reply
      0
      • S Satish Developer

        Hi, i need to display the times on my webpage. They are start time, end time and the reultant time. i wrote the following code. TimeSpan _starttime = DateTime.Now.TimeOfDay; TimeSpan _endtime = DateTime.Now.TimeOfDay; TimeSpan _finaltime = _endtime.Subtract(_starttime); Response.write("Start Time: " + _starttime + "-- End Time: " + _endtime + "-- Finaltime:" + _finaltime); i am getting result as 02:45:27.9085452-- End Time: 02:52:59.2926579-- Finaltime:00:07:31.3841127 Here i am getting milliseconds...how to avoid this in displaying. i want to display time as 02:45:27

        G. Satish

        S Offline
        S Offline
        SachinKumar M
        wrote on last edited by
        #3

        use DateTime.Now.ToString("hh:mm:ss")

        1 Reply Last reply
        0
        • S Satish Developer

          Hi, i need to display the times on my webpage. They are start time, end time and the reultant time. i wrote the following code. TimeSpan _starttime = DateTime.Now.TimeOfDay; TimeSpan _endtime = DateTime.Now.TimeOfDay; TimeSpan _finaltime = _endtime.Subtract(_starttime); Response.write("Start Time: " + _starttime + "-- End Time: " + _endtime + "-- Finaltime:" + _finaltime); i am getting result as 02:45:27.9085452-- End Time: 02:52:59.2926579-- Finaltime:00:07:31.3841127 Here i am getting milliseconds...how to avoid this in displaying. i want to display time as 02:45:27

          G. Satish

          K Offline
          K Offline
          keyur satyadev
          wrote on last edited by
          #4

          various way to achieve this but easiest way is as sachin describe DateTime.now.ToString("hh:mm:ss")//suggested Or altername when you bind the data its change the string format(for knowledge purpose) Regards Keyur Satyadev

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups