Timezone Settings
The range 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 range expects this format and returns this format. It is'local'by default if the date-times don't contain any timezone informationdisplayTimezone- the calendar displays everything in this timezone. The date-times will be converted from thedataTimezoneand displayed accordingly. It is'local'by default
Invalids as well as marked, colored and labels date-times will all be interpreted in dataTimezone when they contain no timezone info and will be shown in displayTimezone on the calendar.
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;
$('#datepicker').mobiscroll().datepicker({
controls: ['calendar', 'time'],
select: 'range',
dataTimezone: 'utc',
displayTimezone: 'local ',
timezonePlugin: mobiscroll.dayjsTimezone,
});
Selected range 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: ' '
});
$(function () {
$('#demo')
.mobiscroll()
.datepicker({
timezonePlugin: mobiscroll.dayjsTimezone,
dataTimezone: 'utc',
displayTimezone: 'local',
controls: ['calendar', 'time'],
select: 'range',
onChange: function (ev, inst) {
var valueSpan = $('#selected-value')[0];
var value = inst.getVal();
valueSpan.parentElement.classList.remove('hidden');
valueSpan.innerHTML = 'from: <code>' + value[0] + '</code><br>to:<code>' + value[1] + '</code>';
},
});
});
<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 range is returned in Data Timezone<br>
<span id="selected-value"></span>.
</p>
</div>
</div>