WPF Toolkit, Modified Date Format in DatePicker

the default date format in the DatePicker is "yyyy-mm-dd" but I need "dd-mm-yyyy". This one solution doesn't work for me.

+2


source to share


3 answers


The date is displayed using CultureInfo.CurrentCulture

, that is, the Windows regional settings selected by the user in the Control Panel and it seems that they cannot be changed. However, it doesn't really matter as the user prefers setting the date and time.



+1


source


This is a fairly old question (marked somewhat incorrectly as "answered"). If you need to use a specific date format for a WPF DatePicker control, but don't want to open source (which is actually downloadable) for it, you can always specify a DateFormat for the entire UI, or set it for each DatePicker control.

In my application, I used the following in the Application_Startup event:

Private Sub Application_Startup(ByVal sender As Object, ByVal e As System.Windows.StartupEventArgs) Handles MyBase.Startup

   ' other application initialization code here

   Dim culInfo As Globalization.CultureInfo = New System.Globalization.CultureInfo("en-us")
   Dim dtinfo As Globalization.DateTimeFormatInfo = New System.Globalization.DateTimeFormatInfo() With {
       .ShortDatePattern = "dd-MMM-yyyy",
       .ShortTimePattern = "hh:mm:ss tt",
       .TimeSeparator = ":",
       .MonthNames = System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat.MonthNames(),
       .AbbreviatedMonthNames = System.Globalization.CultureInfo.InvariantCulture.DateTimeFormat.AbbreviatedMonthNames(),
       .DateSeparator = "-"}

 culInfo.DateTimeFormat = dtinfo
 System.Threading.Thread.CurrentThread.CurrentCulture = culInfo

      



Note that this will set the format for the concise format throughout the application (which is what I wanted, instead of going through and applying culture to each instance of the date picker above, based on another StackOverflow post, I don't remember exactly where he was (or I would name the author) but hope this helps anyway!

Kirk

+3


source


If you want to specify this format for your date, you should do something like this:

DatePicker datetimepicker;
datetimepicker.SelectedDate.Value.ToString("yyyy-MM-dd");

      

datetimepicker.SelectedDate.Value

is DateTime Object

, so you can manipulate as you see fit.

+3


source







All Articles