Can someone explain reddit's created_utc and how to convert it into a usable format in php

StackOverflow https://stackoverflow.com/questions/16801162

  •  30-05-2022
  •  | 
  •  

سؤال

Im looking at http://www.reddit.com/user/MrLuxan/about.json and it gives the created_utc as 1304465246.0 but not sure how it match up with anything on PHP:date. Can anyone explain it to me and give how I can turn it into a usable format

هل كانت مفيدة؟

المحلول

Seems to be a UNIX-timestamp and you can convert it to something human-readable by doing the following:

$timestamp = 1304465246;

echo date('m/d/Y', $timestamp);

and you will get 05/04/2011 back.

Have a look at PHP: date for on how you can format it to your needs better.

نصائح أخرى

It's a unix timestamp. Convert it using the DateTime object:

$dt = new DateTime('@'.'1313790243');
echo $dt->format('Y-m-d H:i:s'); // output: 2011-08-19 21:44:03

You can also use the DateTimeZone object to convert it to your timezone (or whichever timezone you prefer):

$dt->setTimeZone(new DateTimeZone('America/New_York'));
echo $dt->format('Y-m-d H:i:s'); // output: 2011-08-19 17:44:03
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top