hello guys
can any one tell how to get a system date. is there any function to get system date. as because of this i am stuck with my uni ass
any help will be appriciated
s.s.harish
hello guys
can any one tell how to get a system date. is there any function to get system date. as because of this i am stuck with my uni ass
any help will be appriciated
s.s.harish
You'll want to use the functions in time.h. Here's a good reference:
http://www.infosys.utas.edu.au/info/...ib.html#time.h
so if i declare a instnace of the struct tm i will able to get the vales of the date. is thats something like this
struct tm t;
t.tm_mday;
t.tmmon;
t.tm_year;
is this correct.
s.s.harish
Well, that's a data structure for holding time information. There's a function (I think it's time()) that will actually return that structure filled with the current information. There are then numerous formatting functions you can use. And tm might be typedef'ed - I'm not sure, so just be aware.
And before posting code, please read the sticky at the top of the C forum regarding posting code, and learn how to use code tags.
thax very much sean_mackrory
Here's a simple example.There's also a function called strftime(), which will format a time structure pointer (tm) to a string.Code:#include <stdlib.h> #include <stdio.h> #include <time.h> int main(void) { time_t now = time(NULL); struct tm *t = localtime(&now); printf( "%d\n", t->tm_mon+1 ); printf( "%d\n", t->tm_mday ); printf( "%d\n", t->tm_year+1900 ); printf( "%d\n", t->tm_hour ); printf( "%d\n", t->tm_min ); printf( "%d\n", t->tm_sec ); return 0; }
allright swoopy
i got it. cheers swoopy
By the way, here's an example of how to use strftime().
There's a good library reference here:Code:time_t now = time(NULL); struct tm *t = localtime(&now); char date_time[30]; strftime( date_time, sizeof(date_time), "%x %X", t ); printf( "%s\n",date_time );
www.cppreference.com
Last edited by swoopy; 03-03-2005 at 09:13 PM.