note 107839 deleted from function.strtotime by peehaa
| From: | peehaa@php.net | Date: | Fri, 06 Jan 2017 16:03:47 +0000 |
| Subject: | note 107839 deleted from function.strtotime by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-208728@lists.php.net to get a copy of this message | ||
Note Submitter: darylblake at gmail dot com
----
I was doing work with cisco phone systems, and thy record their times as NTP Format.
strtotime() doesnt process the whole NTP timestamp, off the bat, so if you want a quick function to
work I bashed this together pretty quickly, there are probably more efficent ways of processing
this, but it gets the job done. Enjoy.
[code]
<?php
//Note: I ran this in PHP 5.3.x
function NTPtoUnixtime($ntptime)
{
$explodedNTPtime = explode(" ", $ntptime,2);
$startOfDay = strtotime("Today");
$timeThroughDay = strtotime($explodedNTPtime[0]) - $startOfDay ;
return strtotime($explodedNTPtime[1])+$timeThroughDay;
}
$ntpTime = "09:49:22.897 NZDT Mon Feb 20 2012"; //NTP time to convert.
echo NTPtoUnixtime($ntpTime);
//produces: 1329684562
// Which equates to: Mon 20 Feb 2012 09:49:22 NZDT GMT+13
?>
[/code]