How to change culture to a DateTimepicker or calendar control in .Net
Asked Answered
R

6

15

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?

Respire answered 28/10, 2008 at 1:27 Comment(1)
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
L
10

It doesn't seem to be possible to change the culture. See this KB article.

Lingenfelter answered 28/10, 2008 at 13:1 Comment(3)
Link to KB article is dead... :( They should've fixed it by now... it's 8 years later...Feeble
Both these links are down nowZion
KB article from the webarchive web.archive.org/web/20110718101517/http://support.microsoft.com/…Batrachian
K
5

Based on previous solution, I think the better is:

dateTimePicker.Format = DateTimePickerFormat.Custom;
dateTimePicker.CustomFormat = Application.CurrentCulture.DateTimeFormat.ShortDatePattern;
Kairouan answered 8/1, 2010 at 14:58 Comment(1)
Returns "dd-MMM-yy" for me, how does that help to change the culture?Elysian
D
0

For DateTimePicker

dtp.Format = DateTimePickerFormat.Custom;
dtp.CustomFormat = "yyyy-MM-dd"; // or the format you prefer
Dehnel answered 28/10, 2008 at 1:55 Comment(2)
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
V
0
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("fr");
System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture;
Vernon answered 15/1, 2009 at 20:57 Comment(1)
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
D
-1

I think there is detour.

  1. set event handler "ValueChanged"
  2. code

    dateTimePicker.Format = DateTimePickerFormat.Custom;
    string[] formats = dateTimePicker.Value.GetDateTimeFormats(Application.CurrentCulture);
    dateTimePicker.CustomFormat = formats[0];
    
Delois answered 29/12, 2009 at 1:54 Comment(1)
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
P
-1

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;
Preclinical answered 1/10, 2019 at 6:52 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.