Date changes between Client-Side and Server-Side

I am building (using a code) a system for booking accommodations.
After the user selects a room and enters dates, the data is sent to the server-side and there the costs are calculated.

I encountered the following problem: The dates selected by the user sent to the server-side and there it changes to the date of the previous day.

I understand that this is probably due to a difference between the time on my computer and the time on the server computer (located elsewhere in the world).

What is the right way to handle it so that it will work for customers from different time zones and also for Daylight saving time ?

I will note that the business for which I am building the site is from Israel and the vast majority of customers are from Israel, so I prefer to use Israel time rather than server time.

Attaches examples with sample prints:

client-side:

console.log("checkin date on client-side: " + $w('#datePicker1').value);
let arrayOfReturn = checkDatesAndPrices($w('#datePicker1').value, $w('#datePicker2').value); //send dates to function on server-side

server-side:

export function checkDatesAndPrices(checkinDate, checkoutDate) {
    console.log("checkin date on server-side: " + checkinDate);
     .....
}

The prints:

checkin date on client-side: Mon Dec 14 2020 00:00:00 GMT+0200 (Israel Time (Winter))

checkin date on server-side: Sun Dec 13 2020 22:00:00 GMT+0000 (Coordinated Universal Time)

Thank you!

I had something similar, solved it with date-fns (an NPM you can install). Idea is to get the time offset from Israel (or any other place in the world) thru browser, add that time to a new (UTC)-date and send that one to the server.

import { add } from 'date-fns';


let datStartDateTemp = new Date($w('#datePicker1').value);
 let utcTimeOffset = datStartDateTemp.getTimezoneOffset()/60;
 let datStartDateTempUTC = add(new Date(datStartDateTemp), { hours: utcTimeOffset });

Let me know if it works for you, I’m also horsing around with the same problem.

Something else that would work:

On the client:
$w ( ā€˜#datePicker1’ ). value.toDateString()

And on the server:

let useDate = Date.parse(receivedDateValue);