GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 29-Oct-2003, 19:18
MrSmiley MrSmiley is offline
New Member
 
Join Date: Oct 2003
Posts: 1
MrSmiley is an unknown quantity at this point

Time Problem in Program


Hey I'm Workin on a program that calculates age. My Problem is that I need to access the computer time and somehow compare it to the birthdate input. I tryed to use ctime, but it doesnt work the way i need it to.


ex:
the user inputs a b-date: 08/23/1943
the program has to calculate the date using the computers time. ctime gives me Wed Oct 29 21:03:27 2003. is there a way to convert 08/23/1943 to the ctime format? or the opposite? if anyone can help me that would be greatly appriciated.

MrSmiley
p.s. im not asking for the program i am making it, i just need help on using the computers time
  #2  
Old 03-Nov-2003, 12:00
Garth Farley Garth Farley is offline
Invalid Email Address
 
Join Date: May 2002
Location: Ireland
Posts: 638
Garth Farley is a jewel in the roughGarth Farley is a jewel in the roughGarth Farley is a jewel in the rough
ctime will give you what you need. Internally it has a "tm" structure which splits up the string into the chunks you expect, seconds, mins, etc...

Exerpt from /usr/include/time.h
CPP / C++ / C Code:
struct tm {
        int     tm_sec;         /* seconds after the minute [0-60] */
        int     tm_min;         /* minutes after the hour [0-59] */
        int     tm_hour;        /* hours since midnight [0-23] */
        int     tm_mday;        /* day of the month [1-31] */
        int     tm_mon;         /* months since January [0-11] */
        int     tm_year;        /* years since 1900 */
        int     tm_wday;        /* days since Sunday [0-6] */
        int     tm_yday;        /* days since January 1 [0-365] */
        int     tm_isdst;       /* Daylight Savings Time flag */
        long    tm_gmtoff;      /* offset from CUT in seconds */
        char    *tm_zone;       /* timezone abbreviation */
};

The time() functino return the number of seconds since 00:00 Jan 1, 1970. Then the localtime() function does math on this number to work fill in the values into the tm structure above. Here's an example:
CPP / C++ / C Code:
#include <stdio.h>
#include <time.h>

int main(){
  time_t rawtime;
  struct tm * timeinfo;

  time ( &rawtime );  //accepts a pointer
  timeinfo = localtime ( &rawtime );

  printf("It's currently %d:%d:%d", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
}

Good link: www-ccs.ucsd.edu.

GF
 
 

Recent GIDBlogToyota - 2008 September Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
error during program rjd72285 C++ Forum 0 11-Nov-2003 18:49
Display Size and maybe download time BobbyDouglas MySQL / PHP Forum 5 08-Nov-2003 00:18
one program access another? dgoulston C++ Forum 1 07-Oct-2003 11:26
ambiguity in time field zuzupus MySQL / PHP Forum 9 28-Jul-2003 08:40
time Problem zuzupus MySQL / PHP Forum 9 24-Jul-2003 07:02

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 11:25.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.