I believe that the "Unix Time" required for this purpose is not ordinary Unix Time.
The difference? Time zones.
First, let me give you an illustration of what Unix Time means.
Imagine a clock with no date, hours, or minutes. It only counts seconds... but it can count very high, even into the billions.
Again, it only counts seconds, and it knows nothing of time zones. And there is only this one clock, with its count of seconds, to serve the whole world.
At some point in history, naturally, this clock started counting up from zero.
When, exactly, did the clock start counting? It depends who you ask.
As we on the East Coast of the United States reckon time, this happened on Wednesday, December 31, 1969, at 7:00 pm.
A person on the West Coast of the United States would report this as Wednesday, December 31, 1969, at 4:00 pm.
A person in Italy would report it as Thursday, January 1, 1970, at 1:00 am (late Wednesday night, that is).
A person in Japan would report it as Thursday, January 1, 1970, at 9:00 am.
An astronomer or navigator using Greenwich Mean Time would report it as the midnight between Dec. 31, 1969 and Jan. 1, 1970.
Since I am on the East Coast of the United States, I will use my reckoning.
On Dec. 31, 1969, at 7:00:00 pm, the clock showed 0 seconds.
On Dec. 31, 1969, at 7:00:01 pm, the clock showed 1 second.
On Dec. 31, 1969, at 7:00:02 pm, the clock showed 2 seconds.
... ... ...
On Dec. 31, 1969, at 7:01:00 pm, the clock showed 60 seconds.
On Dec. 31, 1969, at 7:01:01 pm, the clock showed 61 seconds.
... ... ...
When the ball in Times Square dropped to signal the New Year 1970, the clock showed 18000 seconds. I reckon as follows:
1 minute = 60 seconds
1 hour = 60 minutes = 60 * 60 seconds = 3600 seconds
time from 7 pm to 12 midnight = 5 hours = 5 * 3600 seconds = 18000 seconds
Let's suppose that on Friday, January 2, 1970, at 9:00 am, I go to check the clock. It shows 136800 seconds. Reckoning:
7 pm Wednesday to 7 pm Thursday = 24 hours
7 pm Thursday to 9 am Friday = 14 hours
24 hours + 14 hours = 38 hours = 136800 seconds
Now, suppose my friend in Japan goes to check the clock, again on Friday, January 2, 1970, at 9:00 am. For him the clock will show only 86400 seconds. That, after all, is the number of seconds in 24 hours, which is the length of time since the clock showed zero.
136800 seconds != 86400 seconds. How is this possible?
Because the time on the USA East Coast != the time in Japan
(that is, my "9:00 am" is NOT the same as his "9:00 am")
All right. Enough playing around. For me (again, on the East Coast of the USA) on Saturday, May 19, 2012, at 6:00 pm, what time will the clock show?
Dec. 31, 1969 to Dec. 31, 2009 = 40 years, of which 10 are leap years
(40 * 365) + 10 = 14610, so 14610 days so far
Dec. 31, 2009 to Dec. 31, 2011 = 2 * 365 days = 730 days
14610 + 730 = 15340 days so far
Dec. 31, 2011 to May 18, 2012 = (31 + 29 + 31 + 30 + 18) days = 139 days
15340 + 139 = 15479 days so far
Check: start = Wed, end = Fri, therefore some number of weeks plus 2 days
15479 = (2211 * 7) + 2, so it seems we're OK
How many seconds in these 15479 days?
1 day = 24 hours = 24 * 3600 seconds = 86400 seconds
15479 days = 15479 * 86400 seconds = 1337385600 seconds... right? Not quite.
One of those "days" has only 23 hours. This is because of a Daylight Saving Time adjustment.
I'm not playing word games here. If you were to start a stopwatch at 12:00 midnight on the night of March 10-11, 2012, and stop it at midnight the next night, it would only show 23 hours, not 24.
So... we really have 1337385600 minus 3600 = 1337382000 seconds so far.
But we are only up to 7 pm on the day before the day we care about. Let's add in another 23 hours = 82800 seconds, to get our final answer:
A look at unixtime.info
confirms this figure.
But if I remember correctly, the Arduino time libraries use a flawed implementation of Unix Time. Their version has the clock start at midnight local
time at the beginning of the year 1970, and it also has the clock shifted forward or backward 3600 seconds at each and every Daylight Saving Time change. Certainly not the simple, straightforward, and uniform count of seconds I have described above.