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. DateTime format

DateTime format

Scheduled Pinned Locked Moved C#
question
5 Posts 5 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.
  • K Offline
    K Offline
    kani98
    wrote on last edited by
    #1

    Does anyone know what format string I need to pass into the DateTime ToString() method to display the current date and time as 08/25/2006 14:48? Thanks.

    R D A S 4 Replies Last reply
    0
    • K kani98

      Does anyone know what format string I need to pass into the DateTime ToString() method to display the current date and time as 08/25/2006 14:48? Thanks.

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #2

      See the "Custom date formatting" section here[^]. /ravi

      My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

      1 Reply Last reply
      0
      • K kani98

        Does anyone know what format string I need to pass into the DateTime ToString() method to display the current date and time as 08/25/2006 14:48? Thanks.

        D Offline
        D Offline
        drdavef
        wrote on last edited by
        #3

        Use the "g" or "G" for general date. The lower case g will give you to minutes as you asked (short date and short time). If you use capital G, you also get seconds (short date and long time. If you do not want the AM/PM notation, use a custom format mask "M/d/yyyy m:h". Note, capitalization is important. Use M for month and m for minutes. If you use h you get 12 hour notation, if you use H, you get 24 hour notation. David

        1 Reply Last reply
        0
        • K kani98

          Does anyone know what format string I need to pass into the DateTime ToString() method to display the current date and time as 08/25/2006 14:48? Thanks.

          A Offline
          A Offline
          AnshShar
          wrote on last edited by
          #4

          DateTime yourDateTime = DateTime.Now; String.Format("{0:M/d/yyyy h:m}", yourDateTime); -Have Fun!

          1 Reply Last reply
          0
          • K kani98

            Does anyone know what format string I need to pass into the DateTime ToString() method to display the current date and time as 08/25/2006 14:48? Thanks.

            S Offline
            S Offline
            Scott Dorman
            wrote on last edited by
            #5

            If you are calling the ToString method of the DateTime object, you would want to use the following: public void sample() { // Create a new DateTime instance set to // 9/1/2006 7:22 PM DateTime d = new DateTime(2006, 9, 1, 14, 22, 0); Console.WriteLine(d.ToString(@"MM/dd/yyyy HH:mm")); }

            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