Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I convert a Unix timestamp back to time?

Tags:

I have the following Unix timestamps.

1301982430 1301982430 1301981474

1301981466 1301981466 1301981066

1301981058 1301981058 1301980388

1301980373 1301980373 1301979082

1301978478 1301978478 1301978478

How do I convert it back to time that's human friendly?

This doesn't seem to work,

strtotime($item->timestamp);
like image 202
esafwan Avatar asked Apr 05 '11 06:04

esafwan


People also ask

How do I convert timestamp to time in Unix?

The getTime method returns the number of milliseconds since the Unix Epoch (1st of January, 1970 00:00:00). To get a Unix timestamp, we have to divide the result from calling the getTime() method by 1000 to convert the milliseconds to seconds. What is this?

Can Unix time go backwards?

Unix time can never go backwards, unless a leap second has been added. This one has happened in practice – 27 times at time of writing. The UTC day gets an extra second added to the end, 23:59:60.

How do I turn a timestamp into a date?

You can simply use the fromtimestamp function from the DateTime module to get a date from a UNIX timestamp. This function takes the timestamp as input and returns the corresponding DateTime object to timestamp.

How do I convert Unix time to normal time in Excel?

For converting 11 digits timestamp to a standard datetime, use the formula as this:=A1/864000+DATE(1970,1,1), A1 is the cell that contains the 11-digits you want to convert to.


2 Answers

You can use the php date function to get the date and time.

echo date('Y-m-d h:i:s',$item->timestamp);
like image 106
Shakti Singh Avatar answered Oct 02 '22 14:10

Shakti Singh


Use date() or strftime.

echo strftime("%Y-%m-%d, %H:%M:%S", time());
echo date('Y-m-d, H:i:s');
like image 42
ThiefMaster Avatar answered Oct 02 '22 14:10

ThiefMaster