Josh Posted June 8, 2016 Share Posted June 8, 2016 I am having trouble parsing a time value from the Steam web API. The value is "20160119T185934Z". When I use the date() function below I get a result of "Sat, 22 Aug 1970, 08:08:59". I can see "01-19-2016" in the original value, which is probably the correct date. How do I parse this for displaying in human-readable format? $displaytime = date('D, d M Y, h:m:s', $timestamp); Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
xtom Posted June 8, 2016 Share Posted June 8, 2016 date() takes a timestamp so don't think that will work. You could probably use substr() three times to extract the 3 parts of the date 2016 01 19 as it looks like it would probably be consistent with the leading zeros on the day/month. Not sure off hand if there is a better way. a quick untested example $string = "20160119T185934Z"; $year = substr($string,0,4); $month = substr($string,5,2); $day = substr($string,7,2); echo $day."/".$month."/".$year; Quote Check out my games: One More Day / Halloween Pumpkin Run Link to comment Share on other sites More sharing options...
martyj Posted June 8, 2016 Share Posted June 8, 2016 There's a couple of ways to do this. Note that date takes in an integer for the second param of a unix timestmap. Easiest but error prone, $displayDate = date($format, strtotime($timestamp)) strtotime can be kind of picky. I recommend something like this: http://php.net/manual/en/datetime.createfromformat.php That way you can specify the format of the input. Then call format on the object to display. Quote Link to comment Share on other sites More sharing options...
Josh Posted June 8, 2016 Author Share Posted June 8, 2016 Cool, that did it. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.