Friday, February 13, 2009

Epoch Time

The time has come.

Tonight, at exactly 23:31:30 UTC, Epoch Time will reach 1234567890! You can watch the countdown here: http://coolepochcountdown.com/

Epoch Time (or Unix Time) can be defined as the number of seconds elapsed since 1 January 1970 00:00:00, not counting leap seconds. It is widely used on many computing systems.

We had an interesting time at work today, coming up with programs in different languages to watch Epoch Time tick by. Here are some of them:

Shell

 while true; do date +%s; sleep 1; done
Perl
 perl -le 'while(true){print time();sleep 1;}'
Haskell
import System.Time
import System.Posix

main :: IO ()
main = do { TOD epoch _ <- getClockTime
       ; putStrLn $ show epoch
       ; threadDelay 1000000
       ; main }
Groovy
groovy -e "while(true){println(new Date().time);sleep(1000)}"
Python
python -c \
  "while True: import time;print time.time();time.sleep(1)"
Java
import java.util.Date;

public class EpochTime {
  public static void main(String[] args) {
    while (true) {
      System.out.println(new Date().getTime() / 1000);
      try {
        Thread.sleep(1000);
      }
      catch (InterruptedException ignore) {
      }
    }
  }
}
HTML
<HTML><body>
<script language="javascript">
if(document.all){
  setInterval(function(){
  time=parseInt(new Date().getTime()/1000);
  document.body.innerText=time;
  },1000);
} else{
  setInterval(function(){
  time=parseInt(new Date().getTime()/1000);
  document.body.textContent=time;
  },1000);
}
</script></body></HTML>

Can you think of any more?

Happy 1234567890 day!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.