comparing time

This is a discussion on comparing time within the C++ Programming forums, part of the General Programming Boards category; ok, I've been looking around quite a bit, but am still having problems with this. I can easily display the ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    3

    comparing time

    ok, I've been looking around quite a bit, but am still having problems with this.

    I can easily display the time with a variety of code, a simple version being..


    time_t rawtim;
    rawtim=time(NULL);
    cout<<ctime(&rawtim);

    ..but
    I need to compare the time(specifically the hour)to see if it has past 17:00

    is there any way I can stick this into a char array to isolate the hour to compare it? or is there another, easier way?

    thanks for any help,
    James
    HB9/KC5ZFZ

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Code:
    #include <iostream>
    #include <ctime>
    using namespace std;
    
    struct tm *timeInfo;
    
    int main ( void )
    {
      time_t rawtime;
      time ( &rawtime );
      timeInfo = localtime ( &rawtime );
      if ( timeInfo->tm_hour < 17 )
        cout<<"Good"<<endl;
      else
        cout<<"Bad"<<endl; 
      return EXIT_SUCCESS;
    }
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Comparing time taken for execution
    By AvaGodess in forum C Programming
    Replies: 15
    Last Post: 10-02-2008, 02:15 PM
  2. Journey time prog 1 minute wrong
    By mike_g in forum C Programming
    Replies: 4
    Last Post: 10-12-2006, 03:41 AM
  3. Is this really true or it's just science fiction?
    By Nutshell in forum A Brief History of Cprogramming.com
    Replies: 145
    Last Post: 04-09-2002, 06:17 PM
  4. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 09:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21