I have a api call using PHP and cURL where I am getting json data back. One of the returned value is for a time field which I need to use to calculate how long until this time. But the time is showing in this format:
2019-03-12T16:53:32Z
It has a letter T and the letter Z at the end. How do I use this to figure out how long left until this time?
It is an ISO8601 date format and can easily be used with the DateTime class in PHP like this.
$in = '2019-03-12T20:53:32Z';
$ind = new DateTime($in);
echo $ind->format('Y/m/d H:i:s'); // check its correctly initialised
$diff = $ind->diff(new DateTime()); // diff between NOW and that datetime
echo $diff->format('Time till that datetime - %m month, %d days, %h Hours, %m Minutes, %s Seconds');
RESULT
2019/03/12 20:53:32
Time till that datetime - 0 month, 0 days, 4 Hours, 0 Minutes, 7 Seconds
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.