Well, I am working with twitch's API currently and I want to echo
the time that the current stream started at. Currently the following is output: 2015-04-11T07:45:20Z seconds
so I am wondering how I would convert this into a readable time. i.e. 07:45:20
.
Asked
Active
Viewed 78 times
0
-
Is `seconds` actually part of that value? – John Conde Apr 11 '15 at 14:53
-
@JohnConde It is part of the output from the API if thats what you mean. – Apr 11 '15 at 14:54
-
[Get time from a date/time string](http://stackoverflow.com/q/6955838), [PHP: Best way to convert a datetime to just time string?](http://stackoverflow.com/q/4349033) – mario Apr 11 '15 at 14:55
1 Answers
2
DateTime::createFromFormat()
allows you to read in non-standard date input and turn it into a DateTime
object that you can then use to format your output however you like:
$date = DateTime::createFromFormat('Y-m-d\TH:i:s\Z *', '2015-04-11T07:45:20Z seconds');
echo $date->format('H:i:s'); // 07:45:20

John Conde
- 217,595
- 99
- 455
- 496