C/unix time question
#1
From my distant past I seem to recall that unix calculated it's time and date by counting seconds from some fixed point in the past, in 1974 or something.
Does anyone know if the C code for this calculation is available as I need to use something similar in a microcontroller and am stuffed if I know how to write it. I'm also too lazy to write it myself if it's already been done :-)
I'd be grateful for any help or suggestions, even pointers to similar code.
Thanks,
Philip.
Does anyone know if the C code for this calculation is available as I need to use something similar in a microcontroller and am stuffed if I know how to write it. I'm also too lazy to write it myself if it's already been done :-)
I'd be grateful for any help or suggestions, even pointers to similar code.
Thanks,
Philip.
#2
The Unix EPOCH time is simply the number of seconds since 1/1/1970. This should be a simple calculation
Just found these, do these help ?
http://www.lovelady.com/unix-source.html
Michael
[Edited by michael_clarkson - 11/13/2003 8:53:49 PM]
[Edited by michael_clarkson - 11/13/2003 8:54:34 PM]
Just found these, do these help ?
http://www.lovelady.com/unix-source.html
Michael
[Edited by michael_clarkson - 11/13/2003 8:53:49 PM]
[Edited by michael_clarkson - 11/13/2003 8:54:34 PM]
#5
Thanks for that folks, I think that unix source site will do the job for me. The thing I didn't want to get into was calculating the date and time from the epoch seconds, I'm sure there is probably a simple formula but with leap years, some months having 30 days and others 31 etc. it looked like a pain to me. It's literally 17 years since I've written any C, or code of any type, so this doesn't fill me with joy! I also know nothing at all about microcontrollers. Luckily it's not an air traffic control centre I'm building :-)
Let's hope the cross compiler for the microcontroller has the header files to do all that time stuff, otherwise I will have to get a header file from somewhere and find out what the formula is :-)
Thanks again.
Let's hope the cross compiler for the microcontroller has the header files to do all that time stuff, otherwise I will have to get a header file from somewhere and find out what the formula is :-)
Thanks again.
#6
Scooby Regular
As long as there's a time.h and an strftime (I don't know about your cross-compiler but they're standard) then you'll be fine. You don't need to do any of the actual calculations yourself.
Trending Topics
Thread
Thread Starter
Forum
Replies
Last Post
ossett2k2
Engine Management and ECU Remapping
15
23 September 2015 09:11 AM
matt12
Engine Management and ECU Remapping
4
14 September 2015 09:36 AM