Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What mathematical algorithm would I use to convert seconds since 1/1/1970 into a usable date/time format (time can be left off)? This includes leap years with extra days and any other additions.

I'm a novice at maths, so please try to keep it in layman's terms (or explain any terminology used).

share|cite|improve this question
Are you looking for an algorithm for Unix Time/ Epoch Time ? You usually ignore leap seconds in calculation. If you are doing something else, I don't think there is any math involved per se, just if loops to check for leap year. – Inquest Jun 6 '12 at 12:32
As @Nunoxic said. However, there are tricks involving modulo computations that let you do this without any loops. Another useful trick is to pretend that the year begins March 1 when you calculate back and forth between day number and the date. This helps because it puts any leap days at the end of the year. This is after all how the old Roman calendar worked, and the reason why leap day is at the end of February (I am oversimplifying somewhat here). The final conversion to and from dates as we use them is quite easy. – Harald Hanche-Olsen Jun 6 '12 at 12:37
@Nunoxic Pretty much. This is ignoring leap seconds (I think that might be a little too pedantic). But it still has to be a mathematical algorithm to determine the correct date (I'm just mentioning leap years as a reminder in-case it's assumed as a simple seconds->days->year esque exercise). – user1433767 Jun 6 '12 at 12:39
Why don't you look at the algorithm used in the implementation of a programming language like C? This should get you started: – Adeel Jun 6 '12 at 13:11
@Adeel - Almost unreadable to me. This is mathematics, after all. Not C. – user1433767 Jun 7 '12 at 1:27

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.