Timezones
The date picker works with local times by default, but ships with support for changing the timezone. The conversions and correct output relies on either of these three external libraries: luxon, moment-timezone and day.js. For installing and using these libraries check out this guide.
There are two angles regarding timezones:
dataTimezone- the datepicker expects this format and returns this format. It is'local'by default if the date-times don't contain any timezone informationdisplayTimezone- the datepicker displays everything in this timezone. The date-times will be converted from thedataTimezoneand displayed accordingly. It is'local'by default
Invalid date-times will be interpreted in dataTimezone when they contain no timezone info and will be shown in displayTimezone on the wheels.
Demo
Data timezone is
Display timezone is
The local timezone your browser is in:
// Extend Day.js with UTC and timezone plugins
dayjs.extend(window.dayjs_plugin_utc);
dayjs.extend(window.dayjs_plugin_timezone);
// Setup Mobiscroll Day.js plugin
mobiscroll.dayjsTimezone.dayjs = dayjs;
mobiscroll.datepicker('#datepicker', {
controls: ['datetime'],
dataTimezone: 'utc',
displayTimezone: 'local ',
timezonePlugin: mobiscroll.dayjsTimezone,
});
Selected date & time is returned in "Data timezone"
dayjs.extend(window.dayjs_plugin_utc);
dayjs.extend(window.dayjs_plugin_timezone);
mobiscroll.dayjsTimezone.dayjs = dayjs;
mobiscroll.setOptions({
locale: ,
theme: ' ',
themeVariant: ' '
});
mobiscroll.datepicker('#demo', {
timezonePlugin: mobiscroll.dayjsTimezone,
dataTimezone: 'utc',
displayTimezone: 'local',
controls: ['datetime'],
onChange: function (ev, inst) {
var valueSpan = document.getElementById('selected-value');
var value = inst.getVal();
valueSpan.parentElement.classList.remove('hidden');
valueSpan.innerText = value;
},
});
<div mbsc-page>
<label>
Pick Date & Time in Display Timezone
<input mbsc-input id="demo" data-input-style="outline" data-label-style="stacked" />
</label>
<div class="mbsc-padding">
<p class="hidden">
Selected date is returned in data timezone<br>
<code id="selected-value"></code>
</p>
</div>
</div>