How can I hide milliseconds (unix timestmap) to utc php

I create web servicesfor android in php, they send time in unix timestamp(milliseconds).

Now I need to convert this to timestamp utc and compare with mysql created_at.

I tried:

$time = 1443001794;
$seconds = $time / 1000;
echo date("d-m-Y", $seconds);

But he always returns '17-01-1970 '.

+4
source share
3 answers

Well, if you want to compare only with mysqltimestamp, you can do like this:

$result = strtotime($mysqlCreateAt);

strtotime converts your timestamp to a unix timestamp, and then you can compare it at any time.

If you want to convert this to utc, try the following:

$date = new DateTime();
$date->setTimestamp(1443001794);
var_dump(gmdate('Y-m-d H:i:s', strtotime($date->format('Y-m-d H:i:s'))));

open UTCtimestamp

+2
source

The MYSQL date format is "yyyy-mm-dd":

:

$time = 1443001794;
echo  date("Y-m-d", $time);

.

$time = 1443001794;
echo  date("Y-m-d H:i:s", $time);
+1

, strtotime .

$db_time = strtotime($created_at); // it will convert your db created at in unix
if($unixtime > $db_time){
 // your code here
}
+1

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


All Articles