Convert JS timestamp to PHP

Asked

Viewed 112 times

0

I wonder how do I convert this JS code to PHP:

A = new Date(2020,1,1,0,0,0).getTime();

Although the result will always "be":

1580522400000

I’m doing like this:

$d = DateTime::createFromFormat('Y-n-j', '2020-2-1');
echo $d->getTimestamp();

1580580050

But the result is not matching. Because there are seconds I believe. How to return the result 1580522400000 with PHP?

  • 2

    Procedural: date("U", strtotime("2020-01-01"));

1 answer

2

Javascript generates value in milliseconds, and PHP in seconds. To compare them, multiply the PHP value by 1000, or divide the JS value by 1000 and take the whole part.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.