A ui:inputDateTime component represents a date and time input field, which is rendered as an HTML input tag of type text on desktop. To apply Lightning Design System styling, we recommend that you use lightning:input with type="datetime-local" instead of ui:inputDateTime.
Web apps running on mobiles and tablets use an input field of type datetime-local for all browsers except Internet Explorer. The value is displayed based on the locale of the browser, for example, MMM d, yyyy and h:mm:ss a, which is returned by $Locale.dateFormat and $Locale.timeFormat.
This is a basic set up of a pair of date and time field with a date picker icon. The client-side controller sets the current date and time in the fields. On desktop, the input tag is wrapped in a form tag; the date and time fields display as two separate fields. The time picker displays a list of time in 30-minute increments.
1/** Client-Side Controller **/2var today = new Date();3// Convert the date to an ISO string4component.set("v.today", today.toISOString());
Selecting A Date and Time on Mobile Devices
When viewed on a mobile or tablet, the ui:inputDateTime component uses the native date and time picker, and the format attribute is not supported in this case. We recommend using the value change handler to retrieve date and time value change on the input field. On iOS devices, selecting a date and time on the date picker triggers the change handler on the component but the value is bound only on the blur event. This example binds the date value to a value change handler.
1<aura:component>23 <aura:attribute name="myDateTime" type="DateTime" />45<!-- Value change handler -->67 <aura:handler name="change" value="{!v.myDateTime}" action="{!c.handleValueChange}" />89 <ui:inputDateTime10 aura:id="mySelectedDateTime"11 label="Select a date and time"12 value="{!v.myDateTime}"13 />1415</aura:component>
The body of the component. In markup, this is everything in the body of the tag.
Aura.Component[]
class
A CSS style to be attached to the component. This style is added in addition to base styles output by the component.
String
disabled
Specifies whether the component should be displayed in a disabled state. Default value is "false".
Boolean
false
displayDatePicker
Indicates if an icon that triggers the date picker is displayed in the field. The default is false.
Boolean
false
errors
The list of errors to be displayed.
Object[]
format
The java.text.SimpleDateFormat style format string.
String
label
The text of the label component
String
labelClass
The CSS class of the label component
String
langLocale
Deprecated. The language locale used to format date time. It only allows to use the value which is provided by Locale Value Provider, otherwise, it falls back to the value of $Locale.datetimeLocale. It will be removed in an upcoming release.
String
required
Specifies whether the input is required. Default value is "false".
Boolean
false
requiredIndicatorClass
The CSS class of the required indicator component
String
updateOn
Updates the component's value binding if the updateOn attribute is set to the handled event. Default value is "change".
String
change
value
The input value of the date/time as an ISO string.