flatpickr converting date and time to Local TimeZone

Created on 10 Oct 2018  路  3Comments  路  Source: flatpickr/flatpickr



https://jsfiddle.net/tj2Lo4z7/233/

Your Environment

I am running following:

  • flatpickr version used: flatpickr v4.5.2
  • Browser name and version: Chrome, V69
  • OS and version: MacOS Mojave, 10.14

Facing this problem when trying to populate the default dates. The code is simple.

const currentTour = {"id":1,"name":"Caribbean T20 League","active":0,"status":1,"startDate":"2018-08-08T00:00:00.000Z","endDate":"2018-09-17T23:59:59.000Z","sportId":2,"totalTeams":6,"totalMatches":34};


const fp = flatpickr(".date", {
    enableTime: true,
  mode: "range",
  dateFormat: "Y-m-d H:i",
  defaultDate: (currentTour.startDate
                        && currentTour.endDate) ? [ currentTour.startDate, currentTour.endDate ]: null

});

As you can see my date in my data currentTour is different vs. what I get in input when the initialisation is completed. Its converting date to Local timeZone (IST)
I have my dates in UTC in DB and I'd also like to show dates in UCT everywhere I am using flatpickr

What I am missing here ?

Most helpful comment

Closing this as a duplicate of #930 and #975. Flatpickr is using the Date object internally and that always uses the local time of the computer.

We're thinking of a solution to this and it will probably come in the form of documentation. Timezones are hard, unfortunately

All 3 comments

One more information I tied including Moment Timezone in document and then initializing a default timezone

 moment.tz.setDefault('Africa/Abidjan');

But its still not helping

The above timeZone information was extracted from https://momentjs.com/downloads/moment-timezone-with-data-2012-2022.js

I also have this issue. Flat-pickr is always choosing the local timezone. I would like to be able to set the timezone of pickr to display in the zone I choose.

Closing this as a duplicate of #930 and #975. Flatpickr is using the Date object internally and that always uses the local time of the computer.

We're thinking of a solution to this and it will probably come in the form of documentation. Timezones are hard, unfortunately

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ibarral picture ibarral  路  3Comments

rafaelrenanpacheco picture rafaelrenanpacheco  路  4Comments

bedakb picture bedakb  路  3Comments

mponton picture mponton  路  3Comments

mgohin picture mgohin  路  4Comments