Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

C/unix time question

Thread Tools
 
Search this Thread
 
Old 13 November 2003, 08:30 PM
  #1  
hedgehog
Scooby Regular
Thread Starter
 
hedgehog's Avatar
 
Join Date: Apr 2003
Posts: 1,985
Likes: 0
Received 0 Likes on 0 Posts
Post

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.
Old 13 November 2003, 08:46 PM
  #2  
michael_clarkson
Scooby Regular
 
michael_clarkson's Avatar
 
Join Date: Jan 2001
Posts: 253
Likes: 0
Received 0 Likes on 0 Posts
Post

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]
Old 13 November 2003, 08:46 PM
  #3  
chiark
Scooby Regular
 
chiark's Avatar
 
Join Date: Jun 2000
Posts: 13,735
Likes: 0
Received 0 Likes on 0 Posts
Post

STFW
Old 13 November 2003, 08:59 PM
  #4  
stevencotton
Scooby Regular
 
stevencotton's Avatar
 
Join Date: Jan 2001
Location: behind twin turbos
Posts: 2,710
Likes: 0
Received 1 Like on 1 Post
Post

It's so so easy, your implementation will already provide a method/function for returning epoch seconds.
Old 13 November 2003, 11:07 PM
  #5  
hedgehog
Scooby Regular
Thread Starter
 
hedgehog's Avatar
 
Join Date: Apr 2003
Posts: 1,985
Likes: 0
Received 0 Likes on 0 Posts
Post

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.
Old 13 November 2003, 11:20 PM
  #6  
stevencotton
Scooby Regular
 
stevencotton's Avatar
 
Join Date: Jan 2001
Location: behind twin turbos
Posts: 2,710
Likes: 0
Received 1 Like on 1 Post
Post

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.
Old 14 November 2003, 07:29 AM
  #7  
Miles
Scooby Regular
 
Miles's Avatar
 
Join Date: Oct 1998
Location: The Granite City/Dallas, Tx.
Posts: 2,519
Likes: 0
Received 0 Likes on 0 Posts
Wink

I wonder what will happen in 2040?

Trending Topics

Old 14 November 2003, 09:34 AM
  #8  
NotoriousREV
Scooby Regular
 
NotoriousREV's Avatar
 
Join Date: Jan 2002
Posts: 11,581
Likes: 0
Received 0 Likes on 0 Posts
Post

People will make lots of money in the run up to 2040 by certifying stuff Y2.04K compliant

*wanders off to register Y2.04K Ltd.*
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
BLU
Non Scooby Related
50
24 September 2015 07:43 PM
ossett2k2
Engine Management and ECU Remapping
15
23 September 2015 09:11 AM
techdw
ScoobyNet General
3
20 September 2015 09:31 PM
Khandaris
ScoobyNet General
11
20 September 2015 12:02 PM
matt12
Engine Management and ECU Remapping
4
14 September 2015 09:36 AM



Quick Reply: C/unix time question



All times are GMT +1. The time now is 06:20 PM.