Skip to main content
A newer version of this page is available. .

Date-Time and Date-Time Offset Masks

  • 10 minutes to read

The date-time and date-time offset masks are similar and have the same functionality. Masks of both types allow users to enter only date and/or time values and support Gregorian, Korean, Taiwanese, and Thai Buddhist calendars. The difference is that date-time offset masks store time offsets from Coordinated Universal Time (UTC) and allow users to change the offset values.

This topic describes date-time and date-time offset masks. For information on other mask types, refer to the following topic: Masks.

Date-Time Masks

You can apply date-time input masks to the Date Edit, Time Edit, and Masked Input components. Mask behavior can differ depending on the client computer’s culture settings.

Date-Time Masks

Run Demo: Date Edit Run Demo: Time Edit Run Demo: Masked Input

Apply a Date-Time Mask

Before you apply a date-time mask to an editor, make sure that the editor meets the following requirements:

DxDateEdit
The Date property is set to a DateTime object.
DxMaskedInput
The Value property is set to a DateTime object or a compatible String (for instance, “11/09/2022”). In the latter case, set the MaskMode property to DateTime.

To apply a date-time mask, assign a predefined or custom pattern to the component’s Mask property:

<DxMaskedInput @bind-Value="@Date"
               Mask="@DateTimeMask.ShortDate">
    <DxDateTimeMaskProperties UpdateNextSectionOnCycleChange="true" />
</DxMaskedInput>

@code{
    DateTime Date { get; set; } = DateTime.Now;
}

The DxDateTimeMaskProperties component allows you to customize mask-related settings. Refer to the following section for more information: Mask Settings.

Date-Time Offset Masks

The Date Edit and Masked Input components support date-time offset input masks. Mask behavior can differ depending on the client computer’s culture settings.

Date-Time Offset Masks

Run Demo: Date Edit Run Demo: Masked Input

Apply a Date-Time Offset Mask

Before you apply a date-time offset mask to an editor, make sure that the editor meets the following requirements:

DxDateEdit
The Date property is set to a DateTimeOffset object.
DxMaskedInput
The Value property is set to a DateTimeOffset object or a compatible String (for instance, “11/09/2022”). In the latter case, set the MaskMode property to DateTimeOffset.

To apply a date-time offset mask, assign a predefined or custom pattern to the component’s Mask property:

<DxMaskedInput @bind-Value="@Date"
               Mask="@DateTimeMask.ShortDate">
    <DxDateTimeOffsetMaskProperties UpdateNextSectionOnCycleChange="true" />
</DxMaskedInput>

@code{
    DateTimeOffset Date { get; set; } = DateTimeOffset.Now;
}

The DxDateTimeOffsetMaskProperties component allows you to customize mask-related settings. Refer to the following section for more information: Mask Settings.

Predefined Masks

Predefined date-time masks allow you to apply a commonly used pattern. The appearance of a mask pattern depends on the current culture. For instance, the same mask can specify different patterns in the U.S. and France.

Users can change the regional format in the SettingsTime & LanguageRegion system dialog. To change the mask culture programmatically, use the Culture property.

Built-in Patterns

Use properties of the DateTimeMask class to apply built-in patterns. Each property is a wrapper for the corresponding standard format string. This technique simplifies the setup process.

<DxDateEdit @bind-Date="Date"
            Mask="@DateTimeMask.ShortDate">
</DxDateEdit>

@code{
    DateTime Date { get; set; } = DateTime.Now;
}

Standard Format Strings

Date-time and date-time offset masks support standard date and time format strings. The table below lists available .NET format strings and corresponding predefined patterns:

Predefined Pattern

.NET Format String

Description

Sample

ShortDate

d

Short date format.

11/9/2022

LongDate

D

Long date format.

Wednesday, November 9, 2022

ShortTime

t

Short time format.

4:30 PM

LongTime

T

Long time format.

4:30:15 PM

ShortDateTime

g

Combines short date and short time masks.

11/9/2022 4:30 PM

G

Combines short date and long time masks.

11/9/2022 4:30:15 PM

f

Combines long date and short time masks.

Wednesday, November 9, 2022 4:30 PM

LongDateTime

F

Full time format according to the FullDateTimePattern property value. In the “en-US” culture, this specifier combines long date and long time masks.

November 9, 2022 4:30:15 PM

RFC1123

R or r

Date-time in the RFC1123 format.

Wed, 09 Nov 2022 16:30:15 GMT

ISO8601

s

Sortable ISO8601 date-time format.

2022-11-09T16:30:15

Universal

u

Universal sortable date-time format.

Date-time offset masks do not support this pattern.

2022-11-09 16:30:15Z

MonthAndDay

M or m

Full month name and day number.

November 9

MonthAndYear

Y or y

Full month name and year number.

November 2022

The example below uses a standard format string to apply a mask pattern to the Date Edit component:

<DxDateEdit @bind-Date="Date"
            Mask="F">
</DxDateEdit>

@code{
    DateTime Date { get; set; } = DateTime.Now;
}

You cannot combine standard masks within a single expression. To get a mask that is not listed in the table above, use custom mask placeholders (see the section below).

Custom Masks

You can combine custom mask placeholders to create custom masks of any complexity. For example, to create the Year-ShortMonth-Date DayOfWeek mask, combine custom mask placeholders as follows:

<DxDateEdit @bind-Date="Date" 
            Mask="yyyy-MMM-dd dddd">
</DxDateEdit>

@code{
    DateTime Date { get; set; } = DateTime.Now;
}

Custom Date-Time Masks

You can use any of the following specifiers to build custom date-time and date-time offset masks:

Specifier or placeholder

Description

Example

d

A day of a month.

1, 2, 3 … 31

dd

A day of a month, with a leading zero for single-digit values.

01, 02, 03 … 31

ddd

A read-only abbreviated name of the day of the week.

Abbreviated day names depend on the current culture.

Mon, Tue, Sat

dddd

A read-only name of the day of the week.

Day names depend on the current culture.

Monday, Tuesday, Saturday

M

A month number.

1, 2, 3 … 12

MM

A month number, with a leading zero for single-digit values.

01, 02, 03 … 12

MMM

An abbreviated month name according to the current culture.

Jan, Feb, Mar

MMMM

A full month name according to the current culture.

January, February, March

y

Last two digits of a year.

1 for 2001, 20 for 2020

yy

Last two digits of a year with a leading zero for single-digit values.

01 for 2001, 20 for 2020

yyyy

A four-digit year.

0001 - 9999

g

A read-only era.

AD or BC

h

Hours in the 12-hour format.

1, 2, 3 … 12

hh

Hours in the 12-hour format, with a leading zero for single-digit values.

01, 02, 03 … 12

H

Hours in the 24-hour format.

0, 1, 2 … 23

HH

Hours in the 24-hour format, with a leading zero for single-digit values.

00, 01, 02 … 23

m

Minutes.

0, 1, 2 … 59

mm

Minutes, with a leading zero for single-digit values.

00, 01, 02 … 59

s

Seconds.

1, 2, 3 … 59

ss

Seconds, with a leading zero for single-digit values.

01, 02, 03 … 59

F or f

One fraction of a second. You can repeat this specifier up to seven times.

Masks that have 4 or more f (F) specifiers are read-only.

1 to 9 (f or F)

01 to 99 (ff or FF)

0000001 to 9999999 (fffffff or FFFFFFF)

tt

A time designator.

AM or PM

t

The first letter of the time designator.

A or P

z

The signed offset of the time zone from UTC, measured in hours, with no leading zeros. In date-time masks, the offset value is read-only.

-1, +5

zz

The signed offset of the time zone from UTC, measured in hours, with a leading zero for single-digit values. In date-time masks, the offset value is read-only.

-01, +05

zzzz

The signed offset of the time zone from UTC, measured in hours and minutes. In date-time masks, the offset value is read-only.

-01:00, +05:00

:

A time separator that depends on the current culture.

: in the en-US culture

/

A date separator that depends on the current culture.

/ in the en-US culture

\

Commands the editor to treat the following symbol as a regular character, not a date-time specifier.

The zz sequence defines a two-digit time zone mask, but the \z\z sequence displays static zz text.

' or "

Allows you to add static (read-only) strings.

‘Current time:’ HH:mm

A custom format string should consist of two or more characters, because a single-character string is interpreted as a standard format string. To use a custom format string that consists of one character (for instance, includes only the d custom format specifier), use one of the following techniques:

  • Include a space before or after the specifier (“d “ or “ d”).
  • Include a percent character before the specifier (“%d”).

Mask Settings

Add the DxDateTimeMaskProperties or DxDateTimeOffsetMaskProperties component to an editor’s markup to customize the mask-related settings.

Mask Navigation Modes

Date-time and date-time offset masks support the following navigation modes:

Regular (default)

Input focus stays within one section until a user moves focus to another section.

Regular Date-Time Masks

Advancing caret

After a user completes input into a mask section, the caret moves to the next editable section. To enable this mode, set the CaretMode property to MaskCaretMode.Advancing.

Date-Time Masks with Advanced Caret

<DxDateEdit @bind-Date="@date" 
            Mask="@DateTimeMask.ShortDate">
    <DxDateTimeMaskProperties CaretMode="@MaskCaretMode.Advancing" />
</DxDateEdit>

@code{
    DateTime date { get; set; } = DateTime.Now;
}

Cascading Updates to Section Values

Date-time and date-time offset masks can include several sections (for instance, the month and day sections). Users can directly enter a required value to a mask section or continuously increase or decrease this section’s value. Refer to the following section for more information User Capabilities.

Set the UpdateNextSectionOnCycleChange property to true to increase or decrease the value of the next mask section after the current section’s value passes the maximum or minimum threshold.

Date-Time Masks Change Section Values Along the Chain

<DxDateEdit @bind-Date="@date" 
            Mask="@DateTimeMask.ShortDate">
    <DxDateTimeMaskProperties UpdateNextSectionOnCycleChange="true" />
</DxDateEdit>

@code {
    DateTime date { get; set; } = DateTime.Now;
}

User Capabilities

  • The Up/Down arrow keys increase/decrease the value of the mask section under the caret.
  • The mouse wheel increases and decreases the value of the mask section under the caret.
  • Keyboard letters select the corresponding month. For example, the j character selects January. Subsequent presses select June and then July.
  • Keyboard numbers select the corresponding month.
  • The Space key moves the caret to the next mask section.
  • The date separator key moves the caret to the next date section.
  • The time separator key moves the caret to the next time section.

User Scenarios

Universal Sortable Date without Time

<DxDateEdit @bind-Date="Value"
            Mask="yyyy-MM-dd">
</DxDateEdit>

@code{
    DateTime Value { get; set; } = DateTime.Now;
}

The yyyy-MM-dd mask allows users to enter dates in the sortable format (year-month-day) without a time section.

Date-Time Masks - Universal Sortable Date without Time

Date with an Abbreviated Month Name

<DxDateEdit @bind-Date="Value"
            Mask="yyyy-MMM-dd">
</DxDateEdit>

@code{
    DateTime Value { get; set; } = DateTime.Now;
}

The yyyy-MMM-dd mask displays dates with abbreviated month names. Users can also enter numbers to specify the corresponding month.

Date-Time Masks - Abbreviated Month Name

Day Name to the Right of a Date

<DxDateEdit @bind-Date="Value"
            Mask="yyyy-MM-dd dddd">
</DxDateEdit>

@code{
    DateTime Value { get; set; } = DateTime.Now;
}

The yyyy-MM-dd dddd mask allows users to enter dates in the sortable format (year-month-day). The name of the corresponding day is displayed to the right of the value and cannot be edited.

Date-Time Masks - Day Name to the Right of a Date