Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

RTC time to UNIX time and EEPROM

Status
Not open for further replies.

bianchi77

Advanced Member level 4
Advanced Member level 4
Joined
Jun 11, 2009
Messages
1,313
Helped
21
Reputation
44
Reaction score
20
Trophy points
1,318
Location
California
Visit site
Activity points
9,442
Guys,
Do you have any ideas on how to convert RTC time into unix time and save it into eeprom ?
Thanks
 

This is the code I use, it is NOT the same as unixtime but it does produce a unique value for every time and date. The real unixtime calculation is quite complicated:
Code:
//*******************************************************************************
// calculate unique seconds number based on 0 being 00:00 01-01-2010
unsigned long GetSecs(unsigned char Year, unsigned char Month, unsigned char Day, unsigned char Hour, unsigned char Min, unsigned char Sec)
{
	unsigned long USecs = 0;

	USecs = ((ulong)Year - 10) * 29462400;	//seconds in 1 year (12 months of 31 days)
	USecs += ((ulong)Month - 1) * 2678400;	//seconds in one month (31 days)
	USecs += ((ulong)Day - 1) * 86400;	//seconds in one day		
	USecs += (ulong)Hour * 3600;		//seconds in one hour
	USecs += (ulong)Min * 60);			//seconds in one minute
	return (USecs + (ulong)Sec);			//+ seconds
}

For simplicity, it assumes that every month has 31 days, this removes the need to work out the days in each month and whether it's a leap year. It means there will be gaps in the numbers produced sometimes but it's good for 90 years or so. Simply reverse the calculation to recover the original date and time.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top