How to set internationalization to a DateTimepicker
or Calendar WinForm
control in .Net when the desire culture is different to the one installed in the PC?
How to change culture to a DateTimepicker or calendar control in .Net
Asked Answered
Today I ran into same problem. It appears that it is not possible. I need custom time format hh:mm in 23:59 format, but no matter what I try (Culture, UICulture, etc.) it always shows 11:59. –
Dump
It doesn't seem to be possible to change the culture. See this KB article.
Link to KB article is dead... :( They should've fixed it by now... it's 8 years later... –
Feeble
Both these links are down now –
Zion
KB article from the webarchive web.archive.org/web/20110718101517/http://support.microsoft.com/… –
Batrachian
Based on previous solution, I think the better is:
dateTimePicker.Format = DateTimePickerFormat.Custom;
dateTimePicker.CustomFormat = Application.CurrentCulture.DateTimeFormat.ShortDatePattern;
Returns "dd-MMM-yy" for me, how does that help to change the culture? –
Elysian
For DateTimePicker
dtp.Format = DateTimePickerFormat.Custom;
dtp.CustomFormat = "yyyy-MM-dd"; // or the format you prefer
Setting the format is not the only thing controlled by the culture. It controls a lot of other things, such as whether the first day of the week is Sunday or Monday. –
Stringer
Format is used only to show current date, but if you want to choose it, datetimepicker control will show full date, based on the regional settings. –
Dc
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("fr");
System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture;
That will not change the regional settings of the Windows, only the current UI culture and current culture of the current thread (as the properties' names suggest). But DateTimePicker control looks only for the regional setting of the Windows, so it doesn't matter. –
Dc
I think there is detour.
- set event handler "ValueChanged"
code
dateTimePicker.Format = DateTimePickerFormat.Custom; string[] formats = dateTimePicker.Value.GetDateTimeFormats(Application.CurrentCulture); dateTimePicker.CustomFormat = formats[0];
GetDateTimeFormats() does not produce format strings (that can be used to do formatting), but formatted strings (the result of formatting). Assigning such a string to .CustomFormat makes no sense. Would vote down answer, but lacking reputation myself... –
Mandragora
Use the telerik radDateTimePicker and write this code , after InitializeComponent(), and Instead of "fa-IR" use your culture.
Application.CurrentCulture = new CultureInfo("fa-IR");
radDateTimePicker1.Format = DateTimePickerFormat.Custom;
radDateTimePicker1.CustomFormat = Application.CurrentCulture.DateTimeFormat.ShortDatePattern;
© 2022 - 2025 — McMap. All rights reserved.