Blazor Date Time Input Overview
The Ignite UI for Blazor Date Time Input allows the user to set and edit the date and time in a chosen input element. The user can edit both date and time portions using an editable masked input. Additionally, one can specify a desired display and input format, as well as min and max values to utilize validation.
Before using the
IgbDateTimeInput, you need to register it as follows:
The easiest way to set the value of the
IgbDateTimeInput component is by passing a Date object to the
IgbDateTimeInput also accepts ISO 8601 strings.
The string can be a full
ISO string, in the format
YYYY-MM-DDTHH:mm:ss.sssZ or it could be separated into date-only and time-only portions.
If a date-only string is bound to the
value property of the component, it needs to be in the format
inputFormat is still used when typing values in the input and it does not have to be in the same format. Additionally, when binding a date-only string, the directive will prevent time shifts by coercing the time to be
Time-only strings are normally not defined in the
ECMA specification, however to allow the directive to be integrated in scenarios which require time-only solutions, it supports the 24 hour format -
HH:mm:ss. The 12 hour format is not supported.
Full ISO string
If a full
ISO string is bound, the directive will parse it only if all elements required by Date.parse are provided.
All falsy values, including
InvalidDate will be parsed as
null. Incomplete date-only, time-only, or full
ISO strings will be parsed as
IgbDateTimeInput has intuitive keyboard navigation that makes it easy to increment, decrement, or jump through different
DateParts among others without having to touch the mouse.
|←||Move one character to the beginning|
|→||Move one character to the end|
|Home||Move to the beginning|
|End||Move to the end|
|Ctrl / Command + ←||Move to the beginning of the date/time section - current one or left one|
|Ctrl / Command + →||Move to the end of the date/time section - current on or right one|
|Focus on a date/time part + ↓||Decrements a date/time part|
|Focus on a date/time part + ↑||Increments a date/time part|
|Ctrl / Command + ;||Sets the current date/time as the value of the editor|
IgbDateTimeInput supports different display and input formats.
It uses Intl.DateTimeFormat which allows it to support predefined format options, such as
full. Additionally, it can also accept a custom string constructed from supported characters, such as
dd-MM-yy. Also, if no
displayFormat is provided, the component will use the
inputFormat as such.
The table bellow shows formats that are supported by the component's
||Date, will be coerced with a leading zero while editing.|
||Date with an explicitly set leading zero.|
||Month, will be coerced with a leading zero while editing.|
||Month with an explicitly set leading zero.|
||Short year format.|
||Full year format.|
||Hours in 12-hour format, will be coerced with a leading zero while editing.|
||Hours in 12-hour format with an explicitly set leading zero.|
||Hours in 24-hour format, will be coerced with a leading zero while editing.|
||Hours in 24-hour format, with an explicitly set leading zero.|
||Minutes, will be coerced with a leading zero while editing.|
||Minutes with an explicitly set leading zero.|
||AM/PM section for 12-hour format.|
To set a specific input format, pass it as a string to the
IgbDateTimeInput. This will set both the expected user input format and the
mask. Additionally, the
inputFormat is locale based, so if none is provided, the editor will default to
If all went well, you should see the following in your browser:
The date time input exposes predefined formats for displaying date/time in various manners. All of the examples below are given in en-US locale.
||7/17/22, 12:00 AM|
||Jul 17, 2022, 12:00:00 AM|
||July 17, 2022 at 12:00:00 AM GMT+3|
||Sunday, July 17, 2022 at 12:00:00 AM Eastern European Summer Time|
||Jul 17, 2022|
||July 17, 2022|
||Sunday, July 17, 2022|
||12:00:00 AM GMT+3|
||12:00:00 AM Eastern European Summer Time|
Furthermore, users can construct a displayFormat string using the supported symbols described in the following table.
||Minimum digits.||7, 17|
||Zero padded.||07, 17|
||Minimum digits.||3, 10|
||Zero padded.||03, 10|
||Minimum digits||1, 12|
||Zero padded||01, 12|
||Minimum digits||1, 23|
||Zero padded||01, 23|
||Minimum digits||1, 59|
||Zero padded||01, 59|
||Minimum digits||1, 59|
||Zero padded||01, 59|
[!Note] Many locales use the same time period string, irrespective of the format specified. Also, it has an effect only if a 12-hour clock is used.
You can specify
maxValue properties to restrict input and control the validity of the component. Just like the
value property, they can be of type
If all went well, the component will be
invalid if the value is greater or lower than the given dates. Check out the example below:
IgbDateTimeInput exposes public
stepDown methods. They increment or decrement a specific
DatePart of the currently set date and time and can be used in a couple of ways.
In the first scenario, if no specific DatePart is passed to the method, a default DatePart will increment or decrement, based on the specified
inputFormat and the internal component implementation. In the second scenario, you can explicitly specify what DatePart to manipulate as it may suite different requirements. Also, both methods accept an optional
delta parameter of type number which can be used to set the stepUp/stepDown step.
spinDelta is a property that can be used to apply a different delta to each date time segment. It will be applied when spinning with the keyboard, mouse wheel or with the
stepDown methods, as long as they don't have the delta parameter provided since it will take precedence over
Try it in the example below:
IgbDateTimeInput component derives from the
IgbInput component, so it exposes all available CSS parts. See Input Styling for reference.