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. checking the current time in C++

checking the current time in C++

Scheduled Pinned Locked Moved C / C++ / MFC
c++help
10 Posts 4 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.
  • N Offline
    N Offline
    nahitan
    wrote on last edited by
    #1

    hi there, Could anybody please help me in this: I need to check the current time in my application after each message that my application receives and whenever it is midnight I reset a counter inside my program. I appreciate any ideas Thanks, Nahitan

    D L 2 Replies Last reply
    0
    • N nahitan

      hi there, Could anybody please help me in this: I need to check the current time in my application after each message that my application receives and whenever it is midnight I reset a counter inside my program. I appreciate any ideas Thanks, Nahitan

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      In your window's message procedure, do something like:

      time_t t;
      time(&t);
      tm *now;
      now = localtime(&t);
      if (now->tm_hour ...)

      "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

      N 1 Reply Last reply
      0
      • D David Crow

        In your window's message procedure, do something like:

        time_t t;
        time(&t);
        tm *now;
        now = localtime(&t);
        if (now->tm_hour ...)

        "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

        N Offline
        N Offline
        nahitan
        wrote on last edited by
        #3

        Thank you very much for your help. When I added your code in my application and when I compile it I get: time_t mt; time(&mt); tm *now; now = localtime(&mt); LogError("ClassA","IClass","jjjjjjjhour=%tm", now->tm_hour); Error executing c:\windows\system32\cmd.exe. Class.dll - 1 error(s), 0 warning(s) Thanks,

        D B 2 Replies Last reply
        0
        • N nahitan

          Thank you very much for your help. When I added your code in my application and when I compile it I get: time_t mt; time(&mt); tm *now; now = localtime(&mt); LogError("ClassA","IClass","jjjjjjjhour=%tm", now->tm_hour); Error executing c:\windows\system32\cmd.exe. Class.dll - 1 error(s), 0 warning(s) Thanks,

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          So which of the three staments is in error? What does %tm do?

          "Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman

          "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

          1 Reply Last reply
          0
          • N nahitan

            Thank you very much for your help. When I added your code in my application and when I compile it I get: time_t mt; time(&mt); tm *now; now = localtime(&mt); LogError("ClassA","IClass","jjjjjjjhour=%tm", now->tm_hour); Error executing c:\windows\system32\cmd.exe. Class.dll - 1 error(s), 0 warning(s) Thanks,

            B Offline
            B Offline
            Bram van Kampen
            wrote on last edited by
            #5

            You confused the poor compiler somewhere. Set a few breakpoints, and find out what's happening. Work with Asserted Values, Run Trivial Examples, Write a Dedicated App to take just this step (Can be a Dialog based App,Call your code in OnInitApp() ). This is called 'Debugging'. The above are the steps I would take, and in that following order. I bet that Step One will lead you to the solution. It may be slow and tedious, but that's what writing software is about. Let me know how you're getting on. :rose:

            Bram van Kampen

            N 1 Reply Last reply
            0
            • B Bram van Kampen

              You confused the poor compiler somewhere. Set a few breakpoints, and find out what's happening. Work with Asserted Values, Run Trivial Examples, Write a Dedicated App to take just this step (Can be a Dialog based App,Call your code in OnInitApp() ). This is called 'Debugging'. The above are the steps I would take, and in that following order. I bet that Step One will lead you to the solution. It may be slow and tedious, but that's what writing software is about. Let me know how you're getting on. :rose:

              Bram van Kampen

              N Offline
              N Offline
              nahitan
              wrote on last edited by
              #6

              I can't figure out what to do. I changed the code to: time_t mt; time(&mt); tm *now; now = localtime(&mt); if (now->tm_hour==16){LogError("AClass","BProcess","Hour is 4 pm");} I still get the same error message Without these 5 lines of code, I do not get any error. I even took out the if statement and I still get the error! :confused:

              B 2 Replies Last reply
              0
              • N nahitan

                hi there, Could anybody please help me in this: I need to check the current time in my application after each message that my application receives and whenever it is midnight I reset a counter inside my program. I appreciate any ideas Thanks, Nahitan

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

                #include < windows.h > #include < stdio.h > void main(){ SYSTEMTIME sysTime; GetLocalTime(&sysTime); printf("\nHour = %d",sysTime.wHour); //if sysTime.wHour == ...) // do...stuff }

                My Articles : KitKat - A Very Simple Pseudo-RootKit (unedited) SpyNet - An Application Specific Keylogger(unedited)

                1 Reply Last reply
                0
                • N nahitan

                  I can't figure out what to do. I changed the code to: time_t mt; time(&mt); tm *now; now = localtime(&mt); if (now->tm_hour==16){LogError("AClass","BProcess","Hour is 4 pm");} I still get the same error message Without these 5 lines of code, I do not get any error. I even took out the if statement and I still get the error! :confused:

                  B Offline
                  B Offline
                  Bram van Kampen
                  wrote on last edited by
                  #8

                  time_t mt; time(&mt); // I would use mt =time(NULL); struct tm *now; now = localtime(&mt); tm is part of the tag Name Space. Not part of cpp as such, but still there // Works in MSVS 5.00 :) :)

                  Bram van Kampen

                  N 1 Reply Last reply
                  0
                  • N nahitan

                    I can't figure out what to do. I changed the code to: time_t mt; time(&mt); tm *now; now = localtime(&mt); if (now->tm_hour==16){LogError("AClass","BProcess","Hour is 4 pm");} I still get the same error message Without these 5 lines of code, I do not get any error. I even took out the if statement and I still get the error! :confused:

                    B Offline
                    B Offline
                    Bram van Kampen
                    wrote on last edited by
                    #9

                    Thinking a bit further. struct tm is part of the C-Runtime, not CPP. That's why you need to qualify tm as a structure tag. In other words, struct tm was declared as a structure tag under 'C' it has therefore no typedef value under cpp. Regards :)

                    Bram van Kampen

                    1 Reply Last reply
                    0
                    • B Bram van Kampen

                      time_t mt; time(&mt); // I would use mt =time(NULL); struct tm *now; now = localtime(&mt); tm is part of the tag Name Space. Not part of cpp as such, but still there // Works in MSVS 5.00 :) :)

                      Bram van Kampen

                      N Offline
                      N Offline
                      nahitan
                      wrote on last edited by
                      #10

                      Thanks a lot, worked perfectly! Thanks thanks thanks,

                      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