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 log date and time

How to log date and time

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestionlearning
3 Posts 3 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.
  • B Offline
    B Offline
    bhangie
    wrote on last edited by
    #1

    Hi I would like to know how to log the date and time and retrieve them at later stage. Someone books to attend a conference i want to log the exact time and date the booking whas made. Do i use the time class and just somehow write these to a file or how do i do that. many thanks Education begins a gentleman, conversation completes him ;)

    V T 2 Replies Last reply
    0
    • B bhangie

      Hi I would like to know how to log the date and time and retrieve them at later stage. Someone books to attend a conference i want to log the exact time and date the booking whas made. Do i use the time class and just somehow write these to a file or how do i do that. many thanks Education begins a gentleman, conversation completes him ;)

      V Offline
      V Offline
      V 0
      wrote on last edited by
      #2

      CTime class. You can get the lot. I usely get the year, month ... in integer and set them via the Format function of CString in a CString (like: yyyy/mm/dd hh/mimi/ss) Have Fun, "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimmy Hendrix

      1 Reply Last reply
      0
      • B bhangie

        Hi I would like to know how to log the date and time and retrieve them at later stage. Someone books to attend a conference i want to log the exact time and date the booking whas made. Do i use the time class and just somehow write these to a file or how do i do that. many thanks Education begins a gentleman, conversation completes him ;)

        T Offline
        T Offline
        toxcct
        wrote on last edited by
        #3

        #include <ofstream>

        void LogMessage (LPCTSTR strMessage) {
        std::ostream OutputFile("C:\\MyFolder\\My_log_file.txt");
        CTime CurrentTime = CTime::GetCurrentTime();
        CString TimeMrk = "[" + CurrentTime.Format("%H:%M:%S") + "] ";

        OutputFile << TimeMrk << strMessage;     //Logging the message into the file, with the format (for example) : "\[18:12:34\] Message to log..."
        

        }


        TOXCCT >>> GEII power

        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