Timestamp converter

CFAbsoluteTime is the primary timestamp format in Mac OS X and iOS.

To convert a CFAbsoluteTime to a UNIX timestamp, you've got to subtract 978307200000, as CFAbsoluteTime is defined as the number of seconds since 2001-01-01 00:00:00 and the UNIX timestamp is defined as the number of seconds since 1970-01-01 00:00:00.

JavaScript uses the same reference date as UNIX, but gives the number of milliseconds, so the JS timestamp is the UNIX timestamp multiplied by 1000.

UNIX timestamp
JS timestamp
Date US (middle-endian) representation mm/dd/yyyy hh:mm:ss

... as I was unable to find a simple CFAbsoluteTime converter in Javascript on the internet, I put this one together. This is the code. (required JQuery)

<p>CFAbsoluteTime: <input type="text" id="t_cf">

<p>UNIX timestamp: <input type="text" id="t_nix">

<p>JS timestamp: <input type="text" id="t_js">

<p>mm/dd/yyyy hh:mm:ss representation</p>
<p><input type="text" id="t_ami"></p>

$(function() {
  var DIFF=978307200000;
  function sett(d) {
  $("#t_cf").keyup(function() { sett(new Date(((+$(this).val())*1000)+DIFF)); });
  $("#t_nix").keyup(function() { sett(new Date((+$(this).val())*1000)); });
  $("#t_js").keyup(function() { sett(new Date((+$(this).val()))); });
  $("#t_ami").keyup(function() { sett(new Date($(this).val())); });