Req #40171 [Com]: There should be a way to create DateTime object from UTC timestamp.
| From: | vin526vin at gmail dot com | Date: | Wed, 08 Jul 2020 02:32:27 +0000 |
| Subject: | Req #40171 [Com]: There should be a way to create DateTime object from UTC timestamp. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-227876@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=40171&edit=1
ID: 40171
Comment by: vin526vin at gmail dot com
Reported by: rkumar at msgme dot com
Summary: There should be a way to create DateTime object from
UTC timestamp.
Status: Wont fix
Type: Feature/Change Request
Package: Feature/Change Request
Operating System: Linux
PHP Version: 5.2.0
Block user comment: N
Private report: N
New Comment:
<?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";
?>
Previous Comments:
------------------------------------------------------------------------
[2007-01-19 18:25:08] derick@php.net
That would be too confusing, as PHP auto casts and "20070119" is something quite different
from the unix timestamp 20070119. What you can do is pass this to the ctor: "@20070119" -
the @ makes it interpret as a Unix timestamp.
------------------------------------------------------------------------
[2007-01-19 16:27:05] 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?
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=40171&edit=1