Mohammed Shopan
Mohammed Shopan

Reputation: 13

how to subtract php date from Javascript date

I create project with php Laravel framework and VueJS and I want to get the difference between server time and client time to process some data time out by Javascript in the client browser.

How can i do that?

I need to change the format of one of the dates to be available to manage by other language functions and property.

how to sub (minus) Carbon::now() got from php api Date.Now() in JS.

I do that to get the difference between client clock and the server.

Upvotes: 0

Views: 158

Answers (1)

Matti Bar-Zeev
Matti Bar-Zeev

Reputation: 106

In order to "speak" in dates, the best practice is to work with timestamps.

The server can have its own timezone offset which is why it is best that it will expose any managed dates in UTC.

The client, on the other hand, will need to convert the UTC timestamp to its locale date, which can be done by adding its timezone offset.

Having said that - you will probably want to calculate the data timeout on the server, since the client can be bypassed, thus exposing a timed-out data to potential hackers.

Hope this helps :)

Upvotes: 1

Related Questions