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. How to format a CTime object

How to format a CTime object

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++tutorial
5 Posts 4 Posters 2 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.
  • Z Offline
    Z Offline
    zengkun100
    wrote on last edited by
    #1

    there is a string represent time like this: Mon, 17 Dec 2007 08:36:48 How can I format this string into a CTime object or some other internal time structure? I've written a function to translate this string into a CTime, but I still wonder is there some library function can do this for me? Thank you! :)

    A Chinese VC++ programmer

    modified on Tuesday, January 15, 2008 3:43:55 AM

    M N 2 Replies Last reply
    0
    • Z zengkun100

      there is a string represent time like this: Mon, 17 Dec 2007 08:36:48 How can I format this string into a CTime object or some other internal time structure? I've written a function to translate this string into a CTime, but I still wonder is there some library function can do this for me? Thank you! :)

      A Chinese VC++ programmer

      modified on Tuesday, January 15, 2008 3:43:55 AM

      M Offline
      M Offline
      Matthew Faithfull
      wrote on last edited by
      #2

      See here[^] for low level time string formatting stuff. To go the other way you'll probably have to roll your own based on sscanf, shouldn't be difficult as long as you're only accepting a well known fixed input format, otherwise you're going to need a parser and that's more complex.

      Nothing is exactly what it seems but everything with seems can be unpicked.

      Z 1 Reply Last reply
      0
      • Z zengkun100

        there is a string represent time like this: Mon, 17 Dec 2007 08:36:48 How can I format this string into a CTime object or some other internal time structure? I've written a function to translate this string into a CTime, but I still wonder is there some library function can do this for me? Thank you! :)

        A Chinese VC++ programmer

        modified on Tuesday, January 15, 2008 3:43:55 AM

        N Offline
        N Offline
        Nitheesh George
        wrote on last edited by
        #3

        Try this COleDateTime class to format the Time/Date. i think this will help you.

        C 1 Reply Last reply
        0
        • N Nitheesh George

          Try this COleDateTime class to format the Time/Date. i think this will help you.

          C Offline
          C Offline
          CPallini
          wrote on last edited by
          #4

          And it can also parse a string representing time. Good hit, indeed. :)

          If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
          [my articles]

          1 Reply Last reply
          0
          • M Matthew Faithfull

            See here[^] for low level time string formatting stuff. To go the other way you'll probably have to roll your own based on sscanf, shouldn't be difficult as long as you're only accepting a well known fixed input format, otherwise you're going to need a parser and that's more complex.

            Nothing is exactly what it seems but everything with seems can be unpicked.

            Z Offline
            Z Offline
            zengkun100
            wrote on last edited by
            #5

            Yes, my own code is based on sscanf, and the string format is fixed like the sample above. strftime, wcsftime, _strftime_l, _wcsftime_l these functions format tm to string, but what I want is formating string to tm or CTime object. Thanks! :)

            A Chinese VC++ programmer

            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