Contact Support
Date time format in Vue Datetimepicker component
28 Mar 20256 minutes to read
Date time format is a way of representing the date and time value in different string format in the textbox.
By default, the DateTimePicker’s format is based on the culture. You can also set the own custom format by using the format
property.
Once the date format property has been defined it will be common to all the cultures.
To know more about the date format standards, refer to the Internationalization Date Time Format section.
The following example demonstrates the DateTimePicker with the custom format (yyyy-MM-dd hh:mm
).
<template>
<div id="app">
<div class='wrapper'>
<ejs-datetimepicker :placeholder="waterMark" :value='dateVal' :format="dateFormat" :floatLabelType="auto"></ejs-datetimepicker>
</div>
</div>
</template>
<script setup>
import { DateTimePickerComponent as EjsDatetimepicker } from '@syncfusion/ej2-vue-calendars';
const waterMark = 'Select a datetime';
const dateVal = new Date();
const dateFormat = 'yyyy-MM-dd hh:mm';
</script>
<style>
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import '../node_modules/@syncfusion/ej2-lists/styles/material.css';
@import "../node_modules/@syncfusion/ej2-vue-calendars/styles/material.css";
.wrapper {
max-width: 250px;
margin: 0 auto;
}
.e-input-group.e-control-wrapper.e-float-input .e-float-text::after {
content: '*';
color: red;
}
</style>
<template>
<div id="app">
<div class='wrapper'>
<ejs-datetimepicker :placeholder="waterMark" :value="dateVal :format="dateFormat" :floatLabelType="auto"></ejs-datetimepicker>
</div>
</div>
</template>
<script>
import { DateTimePickerComponent } from '@syncfusion/ej2-vue-calendars';
export default {
name: "App",
components: {
"ejs-datetimepicker": DateTimePickerComponent
},
data() {
return {
waterMark: 'Select a datetime',
dateVal: new Date(),
dateFormat: 'yyyy-MM-dd hh:mm'
}
}
}
</script>
<style>
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import '../node_modules/@syncfusion/ej2-lists/styles/material.css';
@import "../node_modules/@syncfusion/ej2-vue-calendars/styles/material.css";
.wrapper {
max-width: 250px;
margin: 0 auto;
}
.e-input-group.e-control-wrapper.e-float-input .e-float-text::after {
content: '*';
color: red;
}
</style>
Input formats
The inputFormats
property in the DatetimePicker control allows users to enter dates and times in various formats, providing flexibility in date and time entry. This property accepts an array of predefined formats that the control recognizes, enabling users to input dates in different ways while ensuring they are parsed correctly.
When the user types the date and time in any of the specified input formats, it will be automatically converted to the display format after pressing Enter, the Tab key, or when the input loses focus. This enhances the user experience by allowing intuitive data entry through various custom input formats.
The following example demonstrates the DateTimePicker with multiple input formats.
<template>
<div id="app">
<div class='wrapper'>
<ejs-datetimepicker :placeholder="waterMark" :value='dateVal' :format="dateFormat" :inputFormats: "['dd/MM/yyyy hh:mm','yyyyMMdd hh:mm']" :floatLabelType="auto"></ejs-datetimepicker>
</div>
</div>
</template>
<script setup>
import { DateTimePickerComponent as EjsDatetimepicker } from '@syncfusion/ej2-vue-calendars';
const waterMark = 'Select a datetime';
const dateVal = new Date();
const dateFormat = 'yyyy-MM-dd hh:mm';
</script>
<style>
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import '../node_modules/@syncfusion/ej2-lists/styles/material.css';
@import "../node_modules/@syncfusion/ej2-vue-calendars/styles/material.css";
.wrapper {
max-width: 250px;
margin: 0 auto;
}
.e-input-group.e-control-wrapper.e-float-input .e-float-text::after {
content: '*';
color: red;
}
</style>
<template>
<div id="app">
<div class='wrapper'>
<ejs-datetimepicker :placeholder="waterMark" :value="dateVal :format="dateFormat" :inputFormats="['dd/MM/yyyy hh:mm', 'yyyyMMdd hh:mm']" :floatLabelType="auto"></ejs-datetimepicker>
</div>
</div>
</template>
<script>
import { DateTimePickerComponent } from '@syncfusion/ej2-vue-calendars';
export default {
name: "App",
components: {
"ejs-datetimepicker": DateTimePickerComponent
},
data() {
return {
waterMark: 'Select a datetime',
dateVal: new Date(),
dateFormat: 'yyyy-MM-dd hh:mm'
}
}
}
</script>
<style>
@import '../node_modules/@syncfusion/ej2-base/styles/material.css';
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import '../node_modules/@syncfusion/ej2-lists/styles/material.css';
@import "../node_modules/@syncfusion/ej2-vue-calendars/styles/material.css";
.wrapper {
max-width: 250px;
margin: 0 auto;
}
.e-input-group.e-control-wrapper.e-float-input .e-float-text::after {
content: '*';
color: red;
}
</style>