I am trying to get current Date and Time from back end

I have create a module on back end and i am trying to get current Date and Time.
The problem is that the current Date and Time, from back end, it is not stable - static. Some times it is 5 hours before now and other time it is 10 days after now.
The command that i use is “let myDate=new Date();”

Thank you in advance.

Taking the date / time from backend is a bad idea if you want some correctness in that value. It depends on the server where the content is served from and that could be anywhere in the world. It also depends on various caching mechanisms used by Wix when serving content to the users.

If you want the correct users information date / time take that in a public module and send that to the backend module then it will be correct.

I try all the possible combinations on taking that in a public module and then send it to backend module.
So i get 2 type of feedback:

  1. Current Date and Time from Server, which is wrong as you said.

  2. Correct Date and Time but in a form like this:
    {
    “isFulfilled”: true,
    “isRejected”: false,
    “fulfillmentValue”: “2018-10-17T18:04:40.749Z”
    }, which unfortunately i don’t know how to use. (Of course i use the command “await”).

If you be so kind to help.
We need Correct Date and Time for our Site to function.

Thank you very much in advance.

@brazitikos-asterios Let’s say you do this

let myDate = new Date();

That code you run in your page and then you have a backend module function called getMyThing which takes a parameter, your date.

let result = await getMyThing(myDate);

That will send in the locally created date from your page to your backend and you can use it there how you want.

@andreas-kviby
If the user change the Date and Time of the Machine, i will get the correct?

i also has the same doubt and i am stuck at it , any solution?

@sairamreddy2211 Please add your own issue into a new post instead of bumping up an old post. Explain what you are trying to do, what works, and what doesn’t. Also, add any code in a code block as stated in the Forum Guidelines .

This is an old post and is being closed.