Skip to content
Advertisement

SNMP DateAndTime hex-string convert to human date in PHP

When i want to get the cablemodem event log via SNMP, then i snmpwalk the ‘mib-2.69.1.5.8.1’ oid, but I had the problem because the SNMP store every event date in ‘special’ hex-string called DateAndTime format.

(In my case this is a 8 byte hex-string, like this: 07 B2 01 01 00 0A 14 00)

I would like to convert to human date, like this (1970.01.01. 00:10), so I wrote a PHP function:

JavaScript

This is work, however for some reason I think that this is not the most elegant solution. Am I right?

Advertisement

Answer

For travellers from Google, in this case the device sends an 8 byte SNMP DateAndTime value without timezone information. Check the manual I’ve linked below. However, obtaining the timezone information follows the same principles.


Your code should look like this:

JavaScript

Output:

JavaScript

Please refer to the following manual pages:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement