0

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.

3
  • I think you could get the server clock in a general `YYYY-MM-DD HH:mm:ss' and then you can use the Date Javascript api for the rest. How about that? Have you also considered moment.js? Commented Apr 20, 2019 at 12:09
  • Typically a time value is exchanged, such as milliseconds since 1970-01-01T00:00:00Z. It's a simple form that is easily generated and converted to a Date without parsing or libraries. Commented Apr 20, 2019 at 12:31
  • i try to use Date.parse(date_form_php_api); but do not work correctly Commented Apr 20, 2019 at 12:36

1 Answer 1

1

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 :)

Sign up to request clarification or add additional context in comments.

2 Comments

thank your for help and i found moment js do this timezone offset in js and its has meny feature in this i do this .
@MohammedShopan—you don't need to deal with timezones at all. All you need to to is generate a UTC time value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.