Time formats

NATO Date-Time-Group

The Date_Time_Group is a combined date/time-stamp used mostly in military. A timestamp looks like this:

101705Bjul09

The format is ddHHMMTmmmyy, where dd = day, mmm = 3-letter month, yy = year, HH = hours (24hrs), MM = minutes and T = timezone.

/**
 * Returns the Date Time Group
 * @param int|bool $time UNIX timestamp to encode (false to use current time)
 * @return string DTG
 * @link http://de.wikipedia.org/wiki/Date_Time_Group
 * @link http://en.wikipedia.org/wiki/List_of_military_time_zones
 */
function getDTG( $time = false ) {
    if ($time === false) $time = time();
    $result = date('dHi', $time);
    $tz = (date('Z', $time) / 3600) + 12;   // zero-indexed
    $zonecodes = 'YXWVUTSRQPONZABCDEFGHIKLM';  // J = Juliet time, actual time at observer's point
    // TODO: Exception rule for Y/M time (same timezone, Y=western hemisphere, M=eastern h.)
    $result .= $zonecodes{$tz};
    $result .= strtolower(date('My', $time));
    return $result;
}

Hex Time

The Hexadecimal_time goes back to the year 1863. It splits the day into 16 hex-hours of 256 hex-minutes with each having 16 hex-seconds. Group separator is an underscore (_) and it is read as a fraction of a day, i.e. you can write 8_00_0 as well as .8000 for noon.

function getHT( $time = false, $formatted = true ) {
    if ($time === false) $time = time();
    $timeOfDay = ( date('U', $time)+date('Z', $time) ) % 86400;   // seconds since midnight
    $hexToD    = $timeOfDay*65536/86400;
 
    $result    = dechex($hexToD);
    if ($formatted === true) $result = $result{0} . '_' . $result{1} . $result{2} . '_' . $result{3};
 
    return $result;
}

To get the GeekTime, don't add date('Z') (to have UTC timestamp), use the stamp non-formatted and print out 0x in front.


 
snippets/php/time-formats.txt · Last modified: 2009-07-10 18:06.36 by mbirth
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki Contents powered by Club-Mate Contents powered by BassDrive.com Labelled with ICRA