Jump to content

Recommended Posts

Posted

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);

Let's build cool stuff and have fun. :)

Posted

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;

Check out my games: One More Day / Halloween Pumpkin Run

Posted

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.

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...