Dealing with time in terms of seconds

When adding in or subtracting seconds, such as when dealing with the number of seconds since epoch, I find it much more readable and useful to multiply the number of seconds in a minute by the number of minutes in an hour by the number of hours in a day and so on until I get the period of time I need.

  • 1 for one second
  • 60 for one minute
  • 60 * 60 for hour
  • 60 * 60 * 24 for day
  • 60 * 60 * 24 * 7 for week
  • 60 * 60 * 24 * 365 for year

Of course any value can be played with by changing the appropriate column in much the same way that we learn the ten's and hundred's place in elementary school.

Thus 5 minutes =
60 * 5
As opposed to 300
And 48 hours =
60 * 60 * 48 or 60 * 60 * 24 * 2
As opposed to 172800

You could even choose to write out more complex time frames (e.g. 2 weeks 5 hours and 1 minute as (60 * 60 * 24 * 7 * 2) + (60 * 60 * 5) + (60))

While this can hardly be considered shorthand, it makes human manipulation exceedingly simple without appreciatively impacting script performance.

About author

Reli4nt is a business manager and web developer and the JP behind The JPProject. He is a proverbial jack-of-all-trades-master-of-none, and an all around simple and down to earth kind of guy.