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. General Programming
  3. C#
  4. Format Time

Format Time

Scheduled Pinned Locked Moved C#
questioncom
3 Posts 2 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.
  • N Offline
    N Offline
    Nick Parker
    wrote on last edited by
    #1

    How do I format time so that it will show in terms of HH:MM only ? I am using this:

    this.statusBar1.Text = DateTime.Now.TimeOfDay.ToString();

    and the time is not in the right format. Thanks in advance. Nick Parker

    N 1 Reply Last reply
    0
    • N Nick Parker

      How do I format time so that it will show in terms of HH:MM only ? I am using this:

      this.statusBar1.Text = DateTime.Now.TimeOfDay.ToString();

      and the time is not in the right format. Thanks in advance. Nick Parker

      N Offline
      N Offline
      Neil Van Note
      wrote on last edited by
      #2

      DateTime.Now.ToString("HH:mm") should do it. "hh:mm" for a 12 hour clock. There is also DateTime.Now.ToString("t") and DateTime.Now.ToShortTimeString(), the latter just turns around and executes the former. These last two are locale/culture aware. Regards

      N 1 Reply Last reply
      0
      • N Neil Van Note

        DateTime.Now.ToString("HH:mm") should do it. "hh:mm" for a 12 hour clock. There is also DateTime.Now.ToString("t") and DateTime.Now.ToShortTimeString(), the latter just turns around and executes the former. These last two are locale/culture aware. Regards

        N Offline
        N Offline
        Nick Parker
        wrote on last edited by
        #3

        Thanks Neil that worked great. Just a note to all that read this. When you use DateTime.Now.ToString("HH:mm"); your results will be in military time. However a simple change to DateTime.Now.ToString("hh:mm"); will return "regular" time. Thanks again Neil. :) Nick Parker

        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