Articles in this section
Category / Section

How to change the culture of the DatePicker control in JavaScript?

1 min read

You can set the localization for Syncfusion controls like TextBoxes, DatePicker, etc. based on the browser culture by using the locale property. There is an in-built method called the ej.browserInfo () that returns the browser information as an object.  Then, pass this culture information to the locale property of the components. Refer to the following JavaScript DatePicker code example that demonstrates the same.

 

        $(function () {
            $("#datepick").ejDatePicker({
                value: new Date(),
                // Gets the browser culture name.
                locale: ej.browserInfo().culture.name
            });
        });

 

In the code, ej.browserInfo().culture.name is specified as the value for the locale property. Now, DatePicker control culture is set based on the browser culture. You can also set the browser culture to the controls dynamically by using their instance, as given in the following code example.

 

            //Creates an object for the DatePicker control.
            obj = $("#datepick").data("ejDatePicker");
            // Sets the locale to the control dynamically.
            obj.option("locale", ej.browserInfo().culture.name);

 

To apply a different culture to the components other than the English culture, include the corresponding culture file. So, based on the browser culture, include the corresponding culture file in the application. The globalize.cultures.js is a combined script file for all the cultures, and includes all the culture-related files.

Sample Links:

For globalize.culture.js:

https://ajax.aspnetcdn.com/ajax/globalize/0.1.1/cultures/globalize.cultures.js

For online documentation:  https://help.syncfusion.com/js/localization  


Conclusion

I hope you enjoyed learning how to change the culture of the DatePicker control based on the browser language in JavaScript.

You can refer to our JavaScript DatePicker feature tour page to know about its other groundbreaking feature representations documentation and how 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 forumsDirect-Trac, 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 sign in to leave a comment
Access denied
Access denied