Articles in this section
Category / Section

How to set the date format for JavaScript DatePicker component?

1 min read

This article explains how to set the date format for JavaScript DatePicker Component.

The purpose of formatting is to convert a Date object to display the date in a specific string format, simplifying the date representation. Each culture has a standard format to display the date value. For example, in English culture, the month is displayed first, followed by the date and year, whereas in some other cultures, the date is displayed first, followed by the month and year. Hence, this may create uncertainty in differentiating between the month and date in the displayed value. To overcome this, a custom format can be specified to display the date format as explained below.

By default in the JavaScript DatePicker component, the date format is culture specific, which is convenient for users in a specific culture. Customizing the format to display the date in any required format can be achieved by using the format property of the DatePicker component.


Refer to the following code example to set the format value of the DatePicker component.

 

var datepicker = new ej.calendars.DatePicker({
 
        placeholder: 'Choose a date',

        format: 'dd-MMM-yyyy',

    });

    datepicker.appendTo('#element');

 

 Screenshot:

JavaScript DatePicker displayed date

 

Refer to the following sample link to check the functionality of format API of the DatePicker component.

Sample link:

https://ej2.syncfusion.com/16.1.37/demos/#/material/datepicker/date-format.html


Conclusion

We hope you enjoyed learning about how to set the date format for the JavaScript  DatePicker component.

You can refer to our JavaScript DatePicker Feature tour page to know about its other groundbreaking feature representations and documentation, and to quickly get started for configuration specifications. You can also explore our JavaScript DatePicker Example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsBoldDesk Support, or feedback portal. We are always happy to assist you!

 


 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied