Saturday, November 29, 2008

Swatch Internet Time

Back in 1998, a company called Swatch decided to invent a new method of timekeeping. It didn't catch on, but some people embraced it. If you're one of those people, this is for you. We're going to write a function to convert a time value into a Swatch beat. Our PHP programmer friends already have access to this sort of thing through PHP's date() function.


The following code builds upon two other functions previously published here:

IMPORTANT: To return an accurate result, the time value passed in needs to be UTC/GMT (in other words, without offset). There are two ways to achieve this: set your server's time zone to GMT, or use my UTC time function.


ASP

  1. function swatch(someTime)
  2.     swatch = str_pad(floor(((Hour(someTime) * 3600 * 1000) + (Minute(someTime) * 60 * 1000) + (Second(someTime) * 1000)) / 86400), 3, "0", STR_PAD_LEFT)
  3. end function

View ASP implementation on Snipplr

No comments: