Is datePicker locale dependent

I have the following code on a page, which has an element datePicker1:

$w.onReady(function () {
    $w('#datePicker1').value = new Date(Date.UTC(2019, 5, 25, 0, 0, 0))
}

export function datePicker1_change(event) {
    console.log("datePicker1", $w("#datePicker1").value)
}

When I pick another date in datePicker1, for example ‘2019/06/05’, the Developer Console shows:

datePicker1 "2019-06-04T23:00:00.000Z" // my highlighting

How can I get the date picker to just give me the date I selected “2019-06-05T00:00:00.000Z”

I suspect the one hour difference is something to do with British Summer Time which we are not on at the moment. We are on GMT

I am doing lots of database updates and queries using dates, and this ‘feature’ is giving me grief.

Help!

2 Likes

And if I add a text element to the page to display the date (as suggested in another post):

export function datePicker1_change(event) {
    console.log("datePicker1", $w("#datePicker1").value)
    $w("#dateText").text = $w("#datePicker1").value.toString()
}

then the text field shows

Wed Jun 05 2019 00:00:00 GMT+0100 (British Summer Time)

both in the editor, and on the published site.
Where did British Summer Time come from?

I believe I have found the explanation, and a solution.

When the datePicker’s value is changed by a user to a new date, then it sets the time to 00:00:00.
BUT that date/time is in the timezone for your locality and for the time of year
(Here in the UK we move our clocks forward an hour during the summer).

So to adjust the value of the datePicker.value to a GMT date you need to look at its TimezoneOffset (which is in hours) for your locality and time of year, and subtract it from the datePicker.value

let newDate = $w("#datePicker1").value
let fixedDate = new Date(newDate.getTime() - newDate.getTimezoneOffset()*60000)

If any Wixers read this, perhaps you could suggest adding this to your almost uniformly excellent and comprehensive Help Centre. It would have saved me a couple of days.