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 / C++ / MFC
  4. Time Format

Time Format

Scheduled Pinned Locked Moved C / C++ / MFC
question
9 Posts 6 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.
  • J Offline
    J Offline
    john5632
    wrote on last edited by
    #1

    Hi, I am getting getting time through CTime::GetCurrentTime() but I am getting time in 24 hours format. How can I change it in 12 hours format?

    S L U 3 Replies Last reply
    0
    • J john5632

      Hi, I am getting getting time through CTime::GetCurrentTime() but I am getting time in 24 hours format. How can I change it in 12 hours format?

      S Offline
      S Offline
      Shivanand Gupta
      wrote on last edited by
      #2

      AFTER getting currenttime you can use Format method for changing time format as you want

      1 Reply Last reply
      0
      • J john5632

        Hi, I am getting getting time through CTime::GetCurrentTime() but I am getting time in 24 hours format. How can I change it in 12 hours format?

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        The documentation[^] is always the first place to look.

        It's time for a new signature.

        1 Reply Last reply
        0
        • J john5632

          Hi, I am getting getting time through CTime::GetCurrentTime() but I am getting time in 24 hours format. How can I change it in 12 hours format?

          U Offline
          U Offline
          User 3919723
          wrote on last edited by
          #4

          CTime::GetCurrentTime() returns a CTime object, not a string, so it has not a format. To get the formatted string, have you used the CTime::Format function? Use it with %I instead of %H. P.S.: you cannot read the documentation on MSDN?

          J 1 Reply Last reply
          0
          • U User 3919723

            CTime::GetCurrentTime() returns a CTime object, not a string, so it has not a format. To get the formatted string, have you used the CTime::Format function? Use it with %I instead of %H. P.S.: you cannot read the documentation on MSDN?

            J Offline
            J Offline
            john5632
            wrote on last edited by
            #5

            I am using like

            szTimeDisplay.Format(L"%02d:%02d:%0d",tm.GetHour(),tm.GetMinute(),tm.GetSecond());

            I also tried as you told but not worked?

            A S 2 Replies Last reply
            0
            • J john5632

              I am using like

              szTimeDisplay.Format(L"%02d:%02d:%0d",tm.GetHour(),tm.GetMinute(),tm.GetSecond());

              I also tried as you told but not worked?

              A Offline
              A Offline
              Aescleal
              wrote on last edited by
              #6

              CTime::Format only takes one parameter, and that's a format string. The format is based on strftime rather than the printf style you're expecting. MSDN has an example[^] at the bottom of the page that might give you a leg up in the right direction. Cheers, Ash

              1 Reply Last reply
              0
              • J john5632

                I am using like

                szTimeDisplay.Format(L"%02d:%02d:%0d",tm.GetHour(),tm.GetMinute(),tm.GetSecond());

                I also tried as you told but not worked?

                S Offline
                S Offline
                sharp prospector
                wrote on last edited by
                #7

                use this instead:

                szTimeDisplay = tm.Format(_T("%I:%M:%S"))

                J 1 Reply Last reply
                0
                • S sharp prospector

                  use this instead:

                  szTimeDisplay = tm.Format(_T("%I:%M:%S"))

                  J Offline
                  J Offline
                  john5632
                  wrote on last edited by
                  #8

                  Thanks, how to get AM/PM ?

                  S 1 Reply Last reply
                  0
                  • J john5632

                    Thanks, how to get AM/PM ?

                    S Offline
                    S Offline
                    sharp prospector
                    wrote on last edited by
                    #9

                    use %p

                    szTimeDisplay = tm.Format(_T("%I:%M:%S %p"))

                    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