iOS-style jQuery Date and Time Picker Plugin - mobiscroll
| File Size: | 109 KB |
|---|---|
| Views Total: | 36287 |
| Last Update: | |
| Publish Date: | |
| Official Website: | Go to website |
| License: | MIT |
Mobiscroll is a customizable, iOS, Android, and iOS classic-style jQuery date & time picker for mobile-first web applications.
It allows your users to select dates and times with touch-friendly scrolling wheels in regular form inputs.
Note that the article/demo/download is based on the open-source Mobiscroll v2.17.1. The current Mobiscroll date and time picker is a commercial UI component.
Features:
- Separate date, time, and combined date and time pickers.
- Touch scrolling, mouse wheel input, plus/minus buttons, and three interaction modes: scroller, clickpick, and mixed.
- Built-in Mobiscroll, Android, Android Holo, iOS, jQuery Mobile, Sense UI, and Windows Phone themes.
- Modal, inline, anchored bubble, top, and bottom display modes.
- Custom date and time formats, wheel order, and 12-hour or 24-hour time selection.
- Minimum and maximum dates, disabled dates, recurring weekday restrictions, and valid-date exceptions.
- Configurable hour, minute, and second increments.
- Localized month and weekday names, translated button labels, and right-to-left layouts.
- Configurable Set, Cancel, Clear, and Now buttons.
- Programmatic date selection, value retrieval, and picker lifecycle callbacks.
Basic Usage:
1. Load the CSS files, jQuery, and Mobiscroll's JavaScript modules. Include the iOS theme files for an iOS-style picker.
<link href="css/mobiscroll.animation.css" rel="stylesheet"> <link href="css/mobiscroll.icons.css" rel="stylesheet"> <link href="css/mobiscroll.frame.css" rel="stylesheet"> <link href="css/mobiscroll.frame.ios.css" rel="stylesheet"> <link href="css/mobiscroll.scroller.css" rel="stylesheet"> <link href="css/mobiscroll.scroller.ios.css" rel="stylesheet"> <script src="/path/to/cdn/jquery.js"></script> <script src="js/mobiscroll.core.js"></script> <script src="js/mobiscroll.frame.js"></script> <script src="js/mobiscroll.scroller.js"></script> <script src="js/mobiscroll.util.datetime.js"></script> <script src="js/mobiscroll.datetimebase.js"></script> <script src="js/mobiscroll.datetime.js"></script> <script src="js/mobiscroll.frame.ios.js"></script>
2. Create an input field.
<label for="scroller">Date and time</label> <input type="text" id="scroller" name="scroller" />
3. Initialize the date and time picker.
$(function () {
$("#scroller").mobiscroll().datetime({
theme: "ios",
display: "bottom"
});
});
4. For separate date and time fields, use the date() and time() presets.
<label for="date">Date</label> <input type="text" id="date" /> <label for="time">Time</label> <input type="text" id="time" />
$(function () {
$("#date").mobiscroll().date({ theme: "ios" });
$("#time").mobiscroll().time({ theme: "ios" });
});
Date and Time Picker Examples:
Set a date range and disable weekends
Replace the initialization of #scroller with the code below to limit selection to the next 30 days and disable Saturdays and Sundays.
$(function () {
var today = new Date();
var min = new Date(today.getFullYear(), today.getMonth(), today.getDate());
var max = new Date(today.getFullYear(), today.getMonth(), today.getDate() + 30);
$("#scroller").mobiscroll().date({
theme: "ios",
minDate: min,
maxDate: max,
invalid: ["w0", "w6"],
dateFormat: "yy-mm-dd",
dateOrder: "yymmdd"
});
});
Use 24-hour time and 15-minute intervals
$(function () {
$("#scroller").mobiscroll().datetime({
theme: "ios",
dateFormat: "yy-mm-dd",
dateOrder: "yymmdd",
timeFormat: "HH:ii",
timeWheels: "HHii",
steps: { minute: 15, zeroBased: true },
buttons: ["set", "clear", "now", "cancel"]
});
});
Disable a daily time interval
Use time strings in the invalid array to block a time interval. Add a d property such as "w1" to apply the rule only on Mondays.
$(function () {
$("#scroller").mobiscroll().datetime({
theme: "ios",
timeWheels: "HHii",
timeFormat: "HH:ii",
invalid: [{ start: "12:00", end: "12:59" }]
});
});
Create an inline picker
<label for="inline-date">Choose a date</label> <input type="text" id="inline-date">
$(function () {
$("#inline-date").mobiscroll().date({
theme: "ios",
display: "inline"
});
});
Change the language
Load a localization file after the Mobiscroll modules and before initialization. For example, the Spanish language file:
<script src="js/i18n/mobiscroll.i18n.es.js"></script>
$(function () {
$("#scroller").mobiscroll().date({
theme: "ios",
lang: "es"
});
});
Available Plugin Options:
Date and time selection
minDateEarliest selectable date/time (JavaScriptDate). Defaults to January 1 ofstartYear.maxDateLatest selectable date/time (JavaScriptDate). Defaults to December 31 ofendYearat 23:59:59.startYearFirst year when nominDateis supplied. Defaults to the current year minus 100.endYearLast year when nomaxDateis supplied. Defaults to the current year plus 1.defaultValueInitial wheel date for an empty input. Supply aDate; defaults to the current date and time.invalidArray of unavailable dates, weekday strings ("w0"through"w6"), days of the month, recurring month/day strings (e.g."12/25"), date ranges withstartandendDate objects, or time intervals withstartandendtime strings. An optionaldrestricts a time interval to a date rule.validArray of exceptions toinvalidusing the same date and time rules. Dates outsideminDateandmaxDateremain unavailable.stepsObject withhour,minute,second, andzeroBasedsettings. The interval defaults to 1;zeroBased: truealigns wheel increments to zero.stepHourHour increment. Default: 1.steps.hourtakes precedence.stepMinuteMinute increment. Default: 1.steps.minutetakes precedence.stepSecondSecond increment. Default: 1.steps.secondtakes precedence. A bug in the upper seconds limit calculation uses the minute step and offset.
Date and time formats
dateFormatFormatted date output. Base default:"mm/dd/yy".dateOrderDate wheel order and labels. Base default:"mmddy". Use"yymmdd"for year/month/day wheels.timeFormatFormatted time output. Default:"hh:ii A".timeWheelsTime wheel order and clock format. Default:"hhiiA"; use"HHii"for 24-hour hours and minutes.separatorString between date and time in the combined preset. Default: one space.shortYearCutoffTwo-digit year parsing cutoff. Default:"+10"relative to the current year.
Appearance and layout
themeTheme name, such as"mobiscroll","ios", or"android-holo". Load the corresponding theme files first. Use"auto"or omit the option to select the automatic theme.display"modal","inline","bubble","top", or"bottom". Base default: modal.layoutUse"liquid"for a fluid wheel layout.anchorElement or selector for positioning a bubble picker; defaults to the associated element.contextContainer selector or element for the picker. Default:"body".cssClassAdditional CSS class on the picker container.baseThemeAdditional base theme class used with a custom theme.animatePopup animation setting; usefalseto disable it.headerTextEnable or disable the selected-date header; the date/time preset generates the formatted header when enabled.heightWheel item height in pixels. Base default: 40.rowsNumber of visible wheel rows. Base default: 3.minWidthMinimum wheel width in pixels, as a number or per-wheel array. Base default: 80.maxWidthMaximum wheel width in pixels, as a number or per-wheel array.fixedWidthFixed wheel width in pixels, as a number or per-wheel array.multilineNumber of lines per wheel item. Default: 1.showLabelDisplay wheel labels. Base default: true.selectedLineHeightMatch the selection indicator height to the wheel item height.selectedLineBorderSelected-line border adjustment in pixels.btnClassButton CSS class. Base default:"dwb".btnWidthEnable equal-width buttons. Base default: true.btnPlusClassCSS class for the wheel plus button.btnMinusClassCSS class for the wheel minus button.
Interaction and popup behavior
mode"scroller","clickpick", or"mixed". Default: scroller.readonlyDisable wheel changes globally or on individual wheels with a Boolean array. Default: false.disabledDisable the picker and associated input. Default: false.showOnTapOpen on tap or click. Default: true.showOnFocusOpen when the input receives focus. Default: false.closeOnOverlayDismiss a popup by tapping its overlay. Default: true.scrollLockRestrict background scrolling while a popup is open. Default: true.focusTrapKeep focus inside the modal picker. Default: true.focusOnCloseRestore focus when the picker closes. Default: true, except on iOS 8.mousewheelEnable mouse wheel scrolling. Default: true.tapEnable touch tap handling. Default: true.delayDelay in milliseconds for repeated plus/minus wheel actions. Default: 300.confirmOnTapAllow tapping the selected wheel item to confirm a selection; accepts true, false, or per-wheel settings. Default: true.speedUnitWheel scroll speed coefficient. Default: 0.0012.timeUnitWheel animation time coefficient. Default: 0.08.buttonsArray of built-in button names (set,cancel,clear,now) or custom button definitions. Popup default: Set and Cancel; inline default: no buttons.ariaMessageMessage announced through the picker’s ARIA live region when focus is moved into the popup.
Localization and labels
langLoaded locale identifier. Default:"en".rtlEnable right-to-left layout.setTextSet button label. Default: Set.cancelTextCancel button label. Default: Cancel.closeTextClose button label in live selection mode. Default: Close.clearTextClear button label. Default: Clear.nowTextNow button label. Default: Now.dayTextDay wheel label. Default: Day.monthTextMonth wheel label. Default: Month.yearTextYear wheel label. Default: Year.hourTextHour wheel label. Default: Hours.minuteTextMinute wheel label. Default: Minutes.secTextSecond wheel label. Default: Seconds.ampmTextAM/PM wheel label. Defaults to a nonbreaking space.amTextAM indicator. Default: am.pmTextPM indicator. Default: pm.monthNamesArray of full month names.monthNamesShortArray of abbreviated month names.dayNamesArray of full weekday names, starting with Sunday.dayNamesShortArray of abbreviated weekday names, starting with Sunday.daySuffixText appended to day wheel labels.monthSuffixText appended to numeric month wheel labels.yearSuffixText appended to year wheel labels.
Date and Time Format Tokens:
Use these case-sensitive tokens with dateFormat and timeFormat. For example, yy-mm-dd HH:ii produces 2026-11-25 14:30.
| Token | Meaning |
|---|---|
d / dd |
Day of month / zero-padded day |
D / DD |
Short / full weekday name |
o / oo |
Day of year / zero-padded day of year |
m / mm |
Month number / zero-padded month |
M / MM |
Short / full month name |
y / yy |
Two-digit / four-digit year |
h / hh |
12-hour clock / zero-padded hour |
H / HH |
24-hour clock / zero-padded hour |
i / ii |
Minutes / zero-padded minutes |
s / ss |
Seconds / zero-padded seconds |
a / A |
Localized am/pm / uppercase AM/PM |
'text' / '' |
Literal text / literal apostrophe |
API Methods:
Call methods on the initialized input using .mobiscroll("method", arguments).
Read and update values
getDate(temp)Get the selected JavaScript Date, or null. Pass true for the temporary wheel selection.setDate(date, fill, time, temp, change)Set a Date. Pass true as fill to update the input; time controls scroll animation in seconds. temp targets the uncommitted selection, and change controls the input change event.getVal(temp)Date/time preset alias for getDate.setVal(value, fill, change, temp, time)Set a formatted date/time string or wheel value array; null clears the value. Note the different argument order from setDate.getArrayVal(temp)Get selected wheel values as an array; pass true for temporary values.setArrayVal(values, fill, change, temp, time)Set the wheel values in the configured wheel order.
Control the picker
show(prevAnim, prevFocus)Open the picker. PasstrueforprevAnimto skip animation or forprevFocusto skip automatic focus.hide(prevAnim)Close the picker. Pass true to suppress animation.select()Commit the selection.cancel()Cancel a popup selection and close the picker.clear()Clear the selected value.isVisible()Return whether the picker is visible.enable()Enable the picker and associated input.disable()Disable the picker and associated input.
Configure and manage instances
option(name, value) / option(object)Update settings and reinitialize the existing picker.position(check)Reposition the open picker. Passtrueto skip repositioning when the viewport dimensions are unchanged.attachShow($element, beforeShow)Bind an additional trigger element to the picker, with an optional pre-open function.ariaMessage(text)Send a message to the picker’s live region.getInst()Return the Mobiscroll instance.destroy()Remove the picker and its attached handlers.
Set and retrieve a date
var $picker = $("#scroller");
$picker.mobiscroll("setDate", new Date(), true);
var selected = $picker.mobiscroll("getDate");
Update settings after initialization
$("#scroller").mobiscroll("option", {
dateFormat: "yy-mm-dd",
timeFormat: "HH:ii",
timeWheels: "HHii"
});
Open from an additional button
<button type="button" id="open-picker">Open picker</button>
$("#scroller").mobiscroll("attachShow", $("#open-picker"));
Global Defaults and Date Utilities:
Set defaults before initializing any pickers.
$.mobiscroll.setDefaults({ theme: "ios", display: "bottom" });
Format and parse dates independently of the picker:
var formatted = $.mobiscroll.datetime.formatDate("yy-mm-dd", new Date());
var parsed = $.mobiscroll.datetime.parseDate("yy-mm-dd", formatted);
Events and Callbacks:
| Callback | When it runs |
|---|---|
onThemeLoad(locale, settings, inst) |
During theme loading, before the final settings are merged. |
onInit(inst) |
Picker initialization. |
onBeforeShow(inst) |
Before opening; return false to cancel. |
onMarkupReady($markup, inst) |
After picker markup is created. |
onMarkupInserted($markup, inst) |
After insertion into the document. |
onShow($markup, valueText, inst) |
After the picker is shown. |
onPosition($markup, width, height, inst) |
During positioning; return false to skip default positioning. |
onChange(valueText, inst) |
When a user changes the wheel selection. |
onValueTap($item, inst) |
When a wheel item is tapped. Return false to prevent the tap from selecting that item. |
validate($markup, index, time, direction, inst) |
Additional validation hook after the preset validation. Return false to stop the normal scroll-to-position update. |
onValidated(index, inst) |
After validation and wheel positioning, before formatting the new selection. |
onValueFill(valueText, change, inst) |
When a value is written to the associated input. |
onSelect(valueText, inst) |
When selection is confirmed. |
onCancel(valueText, inst) |
When a popup selection is canceled. |
onClear($markup, inst) |
When the clear action is invoked. |
onBeforeClose(valueText, button, inst) |
Before closing; return false to prevent the ordinary close action. |
onHide(inst) |
After the picker markup is hidden. |
onClosed(valueText, inst) |
After close processing and any selection or cancel handler. If an exit animation runs, this event fires before the animation finishes. |
onDestroy(inst) |
During instance destruction. |
For example, retrieve a JavaScript Date when the user confirms the selection:
$(function () {
$("#scroller").mobiscroll().datetime({
theme: "ios",
onSelect: function (valueText, inst) {
var selectedDate = inst.getDate();
console.log(selectedDate);
}
});
});
Related Resources:
Changelog:
2026-11-25 (Article Update)
- Updated the download link and installation instructions for the MIT-licensed date and time picker.
- Added examples for date restrictions, time intervals, inline pickers, and localization.
- Expanded the API reference to cover configuration options, methods, events, and date and time formats.
v2.17.1 (2015-12-17)
- Fixed clearing values when the picker was closed.
- Improved tap handling.
- Date presets without a day wheel now use the current day of the month.
- Added Catalan localization and corrected several existing translations.
v2.17.0 (2015-10-08)
- Introduced onClosed and onBeforeClose, with onClose retained as a deprecated alias.
- Added focusTrap and allowed onBeforeShow to cancel opening.
- Fixed incorrect wheel values after closing during an animation and a scrolling issue in clickpick mode.
v2.13.2 (2014-10-08)
- Fixed: mousemove and mouseup events were incorrectly detached on swipe end.
- Fixed: Popup was outlined on Chrome / OSX.
- Fixed: Sort handle was generated for group headers.
- Fixed: Incorrect handling of null values.
v2.13.1 (2014-09-24)
- New: Accessibility enhancements: read full date for every day, announce month and year on month navigation, read events and event duration.
- New: Month and year selector.
- Fixed: enable/disable functions.
- New: Allow null value for each component.
- New: Show /hide animation improvements: background overlay will fade in and out, faster and smoother animations.
- Fixed: Time validation.
- New: scale setting which controls the decimal precision.
- New: Datepicker preset.
- New: min and max settings.
- New: invalid setting.
- New: headerText setting.
- New: If the select is grouped and group setting is false, group labels will appear as list dividers.
- New: If multiple selection is enabled, there is no empty space on the top and bottom of the wheel anymore, and value on the middle is not highlighted.
v2.12.0-beta (2014-07-08)
- New: focusOnClose setting.
- Fixed: Time was not set correctly if closeOnSelect was true.
- Fixed: In fullscreen mode calendar was not full width.
- New: onSetDate receives a day object with date and control (where the selection occurred: 'calendar', 'date', 'time' or undefined) properties.
- New: navigate method to display a specific month on the calendar without setting the date.
- New: weekDays option to control the format of week days in the calendar header. Can be full, short or min.
- Fixed: Native input and select elements inside list items were not working (#231).
- Fixed: Be able to display multiple rows in group headers.
- Fixed: 'ng-if' directive can be used inside li's with 'mbsc-' prefix
- New: onNavStart and onNavEnd events on hierarchical navigation.
- New: onItemTap event receives the event object as parameter.
- New: A new control with numeric keys for filling numeric values.
- New: minRange and maxRange settings for minimum and maximum selectable range.
- New: onSetDate receives a day object with date, control (where the selection occured: 'calendar', 'date', 'time' or undefined), and active ('start' or 'end') properties (#222).
- New: showSelector setting.
- New: Brand new default theme.
- New: Theme classes are prefixed with .mbsc- to make the classes less generic and avoid conflicts with other libraries.
- New: iOS7 like checkmark icon for the iOS7 theme multiselection.
- New: New wheel styles for jQuery Mobile and Bootstrap themes.
v2.11.0 (2014-05-15)
- Added: rtl setting for right to left support.
- Added: Support for invalid ranges.
- Added: valid setting to override invalid dates.
- Added: Persian translation and support for jalali dates.
- Fixed: Support for data-val="0".
- Added: Undo functionality.
- Added: itemGroups setting for defining different settings (actions, stages, tap) for different list items.
- Added: altRow setting for alternate line colors.
- Added: fixedHeader setting for fixed group headers.
- Changed: android-ics renamed to android-holo.
- Windows Phone Theme
- Changed: PNG images are replaced with font icons.
v2.10.1 (2014-04-22)
- Added: preventFocus parameter for the show method.
- Added: automatic liquid layout based on screen size.
- Added: support for hierarchical listview in Knockout, Angular and Backbone integration plugins.
- Fixed: Vertical alignment was incorrect with Windows Phone theme.
v2.10.0 (2014-04-11)
- Added yearSuffix, monthSuffix, and daySuffix for localized wheel labels.
- Corrected time step alignment when a minimum time is specified.
- Fixed unwanted virtual keyboard activation and page scrolling when opening the picker.
v2.9.5 (2014-03-07)
- Corrected parseDate and formatDate behavior and date limits.
- Fixed touch handling on older Android devices and added a fallback to English for unavailable translations.
v2.9.4 (2014-02-25)
- Added fixed and liquid layouts, multiline wheel labels, and flexbox-based wheel distribution.
- Improved keyboard focus when opening the popup.
v2.9.3 (2014-02-10)
- Corrected theme and language loading when configured through setDefaults.
v2.9.2 (2014-01-21)
- Added temporary start and end value retrieval to the range picker and corrected active button border styling in the Android ICS theme.
v2.9.1 (2014-01-10)
- Corrected range picker bubble positioning and value assignment, jQuery Mobile theme stacking, and Timespan time limits.
This awesome jQuery plugin is developed by acidb. For more Advanced Usages, please check the demo page or visit the official website.











