-   Programming (
-   -   Questions related to time and date in C. (

suttiwit 09-14-2012 09:45 AM

Questions related to time and date in C.
Hello, I have 2 questions related to time and date in the C Programming Language.
1. How can I translate the output from time(NULL); to the human readable time and (if possible) date?
2. How can I get the date and time from the BIOS or the Hardware Clock and if needed translate it to human readable time and date?

Help would be appreciated. :)

Also, I am really happy with It is the only place to ask Linux and Programming Stuff for me because people at my country don't use linux or program. :)

zhjim 09-14-2012 09:54 AM



# man ctime
To have the man page for date time related C functions.

NevemTeve 09-14-2012 03:49 PM

or: localtime + strftime

suicidaleggroll 09-14-2012 06:30 PM

A quick example:


time_t mytime;
struct tm * ptm;

mytime = time(NULL);
ptm = gmtime(&mytime);
printf("%03i, %04i %02i:%02i\n",ptm->tm_yday+1,ptm->tm_year+1900,ptm->tm_hour,ptm->tm_min);

suttiwit 09-15-2012 01:00 AM

How 'bout: how do I convert the Human Readable time and date in a format and convert it to Epoch. Thanks all. :)

NevemTeve 09-15-2012 01:12 AM

It is already in a format, and what do you mean by 'Epoch'?
PS: strptime is your friend.

All times are GMT -5. The time now is 02:40 AM.