Can someone explain reddit created_utc and how to convert it to useful format in php

I like http://www.reddit.com/user/MrLuxan/about.json and it gives create_utc as 1304465246.0, but not sure how it matches anything in PHP: date . Can someone explain this to me and give how I can turn it into a useful format

+4
source share
2 answers

This 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.

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

+4
source

This is a unix timestamp. Convert it using a DateTime object:

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

You can also use the DateTimeZone object to convert it to your time zone (or depending on which time zone you prefer):

 $dt->setTimeZone(new DateTimeZone('America/New_York')); echo $dt->format('Ymd H:i:s'); // output: 2011-08-19 17:44:03 
0
source

Source: https://habr.com/ru/post/1483227/


All Articles