|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-01-19 16:27 UTC] rkumar at msgme dot com
Description: ------------ The constructor for DateTime object currently takes a string as a parameter. In most of the scenarios that I have encountered I need to create a DateTime object from UTC timestamp. Can the constructor be changed to accept string or integer? PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 03:00:01 2025 UTC |
<?php if (!isset($_SERVER["argv"][0]) || isset($_SERVER['REQUEST_METHOD']) || isset($_SERVER['REMOTE_ADDR'])) { die("<br><strong>This script is only meant to run at the command line.</strong>"); } error_reporting(E_ERROR); $args = getopt("v:c:h:"); $strResult = exec( "/bin/snmpwalk -v ".$args['v']." -c ".$args['c']." ".$args['h']." .1.3.6.1.2.1.25.1.2"); $aryDate = explode("," , str_replace('STRING: ', '', substr($strResult, strpos($strResult, 'STRING')))); $strDate = $aryDate[0].' '.substr($aryDate[1], 0, -2); $d1 = new DateTime($strDate); $d2 = new DateTime(date("Y-m-d H:i:s")); $diff=date_diff($d1,$d2); $totalDiff = $diff->format("%d")*86400+$diff->format("%h")*3600+$diff->format("%i")*60+$diff->format("%s"); echo "TimeDiff:".$totalDiff."\n"; ?>