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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. C++ Date formats

C++ Date formats

Scheduled Pinned Locked Moved C / C++ / MFC
c++visual-studiocomjsontutorial
6 Posts 5 Posters 1 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
    Stevo Z
    wrote on last edited by
    #1

    Hi, I'm working under VS 6 C++ and need to parse date from YYYY-MM-DD HH:MM:SS to any of SYSTEMTIME or tm structures. I'm struggling to use CTime, because it requires to run under MFC(does it? :) ) and I'm creating a COM object. Or is there a way to use CTime while creating COM ? PS : I'm not having problems with parsing "YYYY-MM-DD HH:MM-SS" formated string into Int values and filling them into e.c. SYSTEMTIME structure, but I don't know how to compare two dates created that way. When I try to create FILETIME from SYSTEMTIME (to be able to compere them) using SystemTimeToFileTime(...) method, it doesn't work corretly. I suppose it's beacuse of the source SYSTEMTIME doesn't have all fields set (Day of Week and MILISECONDS - which are for me irrelevant, I can set miliseconds to zero but I don't know how to determine day of week) thanx for any ideas

    J L N S N 5 Replies Last reply
    0
    • S Stevo Z

      Hi, I'm working under VS 6 C++ and need to parse date from YYYY-MM-DD HH:MM:SS to any of SYSTEMTIME or tm structures. I'm struggling to use CTime, because it requires to run under MFC(does it? :) ) and I'm creating a COM object. Or is there a way to use CTime while creating COM ? PS : I'm not having problems with parsing "YYYY-MM-DD HH:MM-SS" formated string into Int values and filling them into e.c. SYSTEMTIME structure, but I don't know how to compare two dates created that way. When I try to create FILETIME from SYSTEMTIME (to be able to compere them) using SystemTimeToFileTime(...) method, it doesn't work corretly. I suppose it's beacuse of the source SYSTEMTIME doesn't have all fields set (Day of Week and MILISECONDS - which are for me irrelevant, I can set miliseconds to zero but I don't know how to determine day of week) thanx for any ideas

      J Offline
      J Offline
      Johpoke
      wrote on last edited by
      #2

      I dont know exactly what your problem is, but maybe this will help SYSTEMTIME ST; GetLocalTime(&ST); CString TimeStamp; TimeStamp.Format("%ld-%ld-%ld%ld:%ld",ST.wYear,ST.wMonth,ST.wDay,ST.wHour,ST.wMinute); Note that you might have to make a simple function which adds a 0 infront of some of the variables for it to look nicer :)

      //Johannes

      1 Reply Last reply
      0
      • S Stevo Z

        Hi, I'm working under VS 6 C++ and need to parse date from YYYY-MM-DD HH:MM:SS to any of SYSTEMTIME or tm structures. I'm struggling to use CTime, because it requires to run under MFC(does it? :) ) and I'm creating a COM object. Or is there a way to use CTime while creating COM ? PS : I'm not having problems with parsing "YYYY-MM-DD HH:MM-SS" formated string into Int values and filling them into e.c. SYSTEMTIME structure, but I don't know how to compare two dates created that way. When I try to create FILETIME from SYSTEMTIME (to be able to compere them) using SystemTimeToFileTime(...) method, it doesn't work corretly. I suppose it's beacuse of the source SYSTEMTIME doesn't have all fields set (Day of Week and MILISECONDS - which are for me irrelevant, I can set miliseconds to zero but I don't know how to determine day of week) thanx for any ideas

        L Offline
        L Offline
        Lane Yu
        wrote on last edited by
        #3

        You can use CRT function mktime() to make a time_t, and then you can do everything you want. Take a look at CTime's source. (c:\Program Files\Microsoft Visual Studio\VC98\MFC\SRC\TIMECORE.CPP ) :)

        1 Reply Last reply
        0
        • S Stevo Z

          Hi, I'm working under VS 6 C++ and need to parse date from YYYY-MM-DD HH:MM:SS to any of SYSTEMTIME or tm structures. I'm struggling to use CTime, because it requires to run under MFC(does it? :) ) and I'm creating a COM object. Or is there a way to use CTime while creating COM ? PS : I'm not having problems with parsing "YYYY-MM-DD HH:MM-SS" formated string into Int values and filling them into e.c. SYSTEMTIME structure, but I don't know how to compare two dates created that way. When I try to create FILETIME from SYSTEMTIME (to be able to compere them) using SystemTimeToFileTime(...) method, it doesn't work corretly. I suppose it's beacuse of the source SYSTEMTIME doesn't have all fields set (Day of Week and MILISECONDS - which are for me irrelevant, I can set miliseconds to zero but I don't know how to determine day of week) thanx for any ideas

          N Offline
          N Offline
          Nibu babu thomas
          wrote on last edited by
          #4

          Zilo(svk) wrote:

          I'm struggling to use CTime, because it requires to run under MFC(does it? )

          You can also use ... _tcsftime


          Nibu thomas A Developer Code must be written to be read, not by the compiler, but by another human being. http:\\nibuthomas.wordpress.com

          1 Reply Last reply
          0
          • S Stevo Z

            Hi, I'm working under VS 6 C++ and need to parse date from YYYY-MM-DD HH:MM:SS to any of SYSTEMTIME or tm structures. I'm struggling to use CTime, because it requires to run under MFC(does it? :) ) and I'm creating a COM object. Or is there a way to use CTime while creating COM ? PS : I'm not having problems with parsing "YYYY-MM-DD HH:MM-SS" formated string into Int values and filling them into e.c. SYSTEMTIME structure, but I don't know how to compare two dates created that way. When I try to create FILETIME from SYSTEMTIME (to be able to compere them) using SystemTimeToFileTime(...) method, it doesn't work corretly. I suppose it's beacuse of the source SYSTEMTIME doesn't have all fields set (Day of Week and MILISECONDS - which are for me irrelevant, I can set miliseconds to zero but I don't know how to determine day of week) thanx for any ideas

            S Offline
            S Offline
            Stevo Z
            wrote on last edited by
            #5

            Thanx guys

            1 Reply Last reply
            0
            • S Stevo Z

              Hi, I'm working under VS 6 C++ and need to parse date from YYYY-MM-DD HH:MM:SS to any of SYSTEMTIME or tm structures. I'm struggling to use CTime, because it requires to run under MFC(does it? :) ) and I'm creating a COM object. Or is there a way to use CTime while creating COM ? PS : I'm not having problems with parsing "YYYY-MM-DD HH:MM-SS" formated string into Int values and filling them into e.c. SYSTEMTIME structure, but I don't know how to compare two dates created that way. When I try to create FILETIME from SYSTEMTIME (to be able to compere them) using SystemTimeToFileTime(...) method, it doesn't work corretly. I suppose it's beacuse of the source SYSTEMTIME doesn't have all fields set (Day of Week and MILISECONDS - which are for me irrelevant, I can set miliseconds to zero but I don't know how to determine day of week) thanx for any ideas

              N Offline
              N Offline
              Niklas L
              wrote on last edited by
              #6

              ...or just use strcmp() if you just need to compare times. It will work on the format you supplied, and it's faster than any conversion you can make. If you're about to make alot of comparisons (like sorting) converting it to a number might be the way to go.

              home

              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