Search code examples
javascriptjquerymomentjsbootstrap-datepicker

bootstrap-datepicker: How to use specific time zone?


I created a small program to select the date using bootstrap-datepicker and write it to MySQL.

The catch is that this date must be local to Europe/Berlin regardless where the user is at the moment.

$(....).datepicker({ startDate: 'today' });

My question is: how do I set startDate to be local to specific timezone without using server side code (PHP) or any other libraries?

I tried using moment + moment-timezone but it's also showing the local browser date.

var todaysDate = moment().tz('Europe/Berlin').format();
$(...).datepicker({ startDate: todaysDate });

Thanks.


Solution

  • Just needed

    moment.tz.setDefault("Europe/Berlin");

    After which moment generated the correct date without using tz(). Also make sure that format matches.

    var todaysDate = moment().format('D MMM YYYY');
    $(...).datepicker({ format: 'dd M yyyy', startDate: todaysDate });