Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux timestamp to PHP

Tags:

php

timestamp

I have the following timestamp:

1342259667654

which when converted with http://www.epochconverter.com/ gives:

Assuming that this timestamp is in milliseconds:
GMT: Sat, 14 Jul 2012 09:54:27 GMT
Your time zone: 14. juli 2012 11:54:27 GMT+2

And that is the correct time, but when using:

echo date("Y-m-d H:i:s", 1342259667654);

I get the following date:

1904-07-24 10:22:47

How can I get with PHP the exact date out of this time stamp?

like image 685
Adnan Avatar asked Jul 14 '12 19:07

Adnan


People also ask

What is Unix timestamp in PHP?

Simply put, the Unix timestamp is a way to track time as a running total of seconds. This count starts at the Unix Epoch on January 1st, 1970 at UTC. Therefore, the Unix timestamp is merely the number of seconds between a particular date and the Unix Epoch.

How can I timestamp in PHP?

Definition and Usage. The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT). Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.

What is epoch in PHP?

In PHP, how to get the epoch timestamp, the number of seconds passed since the epoch? In PHP, you can use the time() function. ts = time(); To get the microsecond together too as a float number, use the microtime(true) function. ts2 = microtime(true);

How to convert a date to a timestamp using PHP?

The Task is to convert a Date to a timestamp using PHP. The task can be done by using the strtotime () function in PHP. It is used to convert English textual date-time description to a UNIX timestamp. The UNIX timestamp represents the number of seconds between a particular date and the Unix Epoch.

How do I print a Unix timestamp in PHP?

To do this in PHP, we can use the strtotime function like so: //Our date string. The format is Y-m-d H:i:s $date = '2019-04-01 10:32:00'; //Convert it into a Unix timestamp using strtotime. $timestamp = strtotime ($date); //Print it out. echo $timestamp; //Our date string.

What are Linux timestamps?

Sometimes, this timestamp is populated, but you can’t depend on the values in it. Linux timestamps hold a number rather than a date and time. This number is the number of seconds since the Unix epoch, which was midnight (00:00:00) on January 1, 1970, in Coordinated Universal Time (UTC).

What is timestamptodatetime function in PHP?

Our custom PHP function timeStampToDateTime takes a timestamp as first parameter, which could be the current timestamp or any other time stamp (maybe a timestamp from a db). It uses the timezone and format to return a human readable date time string.


1 Answers

Your timestamp needs to be divided by 1000:

echo date("Y-m-d H:i:s", 1342259667654/1000);
like image 160
davidethell Avatar answered Sep 22 '22 05:09

davidethell