LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Questions related to time and date in C. (https://www.linuxquestions.org/questions/programming-9/questions-related-to-time-and-date-in-c-4175427238/)

suttiwit 09-14-2012 08: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.
Here:
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 LinuxQuestions.org. 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 08:54 AM

http://www.codingunit.com/c-tutorial...-and-date-in-c

ctime()
mktime()

console:
Code:

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

NevemTeve 09-14-2012 02:49 PM

or: localtime + strftime

suicidaleggroll 09-14-2012 05:30 PM

A quick example:

Code:

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 12: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 12: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 03:28 AM.