c++ check time?

I am trying to make a program that checks if it is midnight, but I can't figure it out. I am using time.h. Can someone please post the code to check if it is midnight?

1 Answer

  • 1 decade ago
    Favorite Answer

    #include <time.h>

    bool isMidnight()


    struct tm *newtime;

    time_t long_time;

    time( &long_time ); /* Get time as long integer. */

    newtime = localtime( &long_time ); /* Convert to local time. */

    bool bIsMidnight = (newtime->tm_hour) == 0 && (newtime->tm_min == 0) && (newtime->tm_sec == 0);

    return bIsMidnight;


    Source(s): msdn
Still have questions? Get your answers by asking now.