reactjsreact-datetime

Is it possible to change the timezone of moment object?


I am developing a reactjs application, I want to set timezone to my application.I am using react-datetime package for date and time selection.

My requirement is, My Application need to works with user's selected timezone. For example, In my profile I set America/losangels timezone but I am in India. so the date pickers need to show/give America/losangels date and time but I am getting IST date and time.

Is it possible to change the react-datetime picker timzone?


Solution

  • Use the moment timezone library.

    You can then set the default timezone that moment will use (docs:

    import moment from 'moment-timezone';
    moment.tz.setDefault("America/New_York");
    

    Now, when react-datetime creates/formats new moments, they should be in this timezone.