This is a migrated thread and some comments may be shown as answers.

Localise display format of dates

12 Answers 486 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
cocowalla
Top achievements
Rank 1
cocowalla asked on 18 Oct 2013, 07:59 AM
How can we automatically display dates in the correct format for users, based on their Windows localisation settings?

e.g.
UK: 20/12/2013
NO: 20.12.2013
US: 12/20/2013
etc

12 Answers, 1 is accepted

Sort by
0
cocowalla
Top achievements
Rank 1
answered on 18 Oct 2013, 11:48 AM
Sorry, I should have said I am actually using a RadGridView, with both read-only and editable date fields

I've now got this working for the dates in display mode by setting this on the grid:

IsLocalizationLanguageRespected="False"

But when I edit dates the date format in the date picker is still wrong?
0
Kalin
Telerik team
answered on 18 Oct 2013, 11:52 AM
Hi Colin,

The DatePicker by default uses the CurrentCulture of the user in order to format the date. You can easily check that if you change the culture of the computer then Clean/Rebuild the solution and run the application - the DatePicker changes the format. You can also the check the DateTimePicker Formatting article for more information.

We'll investigate the scenario with RadGridView and we'll get back to you.

Hope this helps.

Regards,
Kalin
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
cocowalla
Top achievements
Rank 1
answered on 18 Oct 2013, 12:28 PM
Changing CurrentCulture seems to have no effect on DatePicker at all. When I check in code-behind I can see that the Culture property on the DatePicker is null.
0
cocowalla
Top achievements
Rank 1
answered on 18 Oct 2013, 12:38 PM
Ah, disregard that last reply; it *is* changing the date format according to CurrentCulture.

So the only problem I have remaining is that DatePickers in the GridView still don't display the correct format when in edit mode.
0
cocowalla
Top achievements
Rank 1
answered on 18 Oct 2013, 12:58 PM
*sigh* please disregard my disregard!

I've definately confirmed now that changing the CurrentCulture or CurrentUICulture doesn't affect the DatePicker Culture property.

I have it set to nb-NO in Windows, and can confirm this by inspecting Thread.CurrentThread.CurrentUICulture and Thread.CurrentThread.CurrentCulture when debugging.

But the Culture property of the DatePicker remains as 'en-GB' - presumably this is coming from a Language settings somewhere, as I still have English as my language in Windows. I don't want to change the language, or perform any localisation on text - only dates.
0
Kalin
Telerik team
answered on 18 Oct 2013, 01:55 PM
Hi Colin,

What I suggested was to change the Culture from the system settings and to observe the result. As for the scenario with the GridView you can set DataFormatString="d" of the GridViewDataColumn with the dates, this way the format will match the system settings. I have recorded and attached video to show the explained above.

Please let us know if this works for you or we are missing something.

Regards,
Kalin
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
cocowalla
Top achievements
Rank 1
answered on 18 Oct 2013, 03:04 PM
OK, now it's fully working for the GridView.

But on other views I have 'standalone' DateTimePickers with DisplayFormat="Short", and it is still not working.

At runtime I can see that Thread.CurrentThread.CurrentUICulture and Thread.CurrentThread.CurrentCulture are set to 'nbNO', but dates are still displayed in UK format (dd/mm/yyyy) and the Culture property of the DatePicker remains as 'en-GB' - presumably this is coming from a Language settings somewhere, as I still have English as my language in Windows. I don't want to change the language, or perform any localisation on text - only date formats.
0
Kalin
Telerik team
answered on 21 Oct 2013, 01:37 PM
Hi Colin,

In this case I can suggest you to try setting the Culture property of the DatePicker to null as showed below:
Culture="{x:Null}"

This way you will make sure the DatePicker is using the current culture of the computer, please also Clean/Rebuild the solution before running the project.

Please try it and let us know if this has solved the described issue.

Regards,
Kalin
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
cocowalla
Top achievements
Rank 1
answered on 21 Oct 2013, 01:44 PM
Yes, setting the Culture on the RadDateTimePicker to "{x:Null}" fixes this issue and shows dates in the correct format!

It's going to be a real pain having to remember to set the culture to null on all date pickers... is this a bug?
0
Kalin
Telerik team
answered on 22 Oct 2013, 02:31 PM
Hello Colin,
If you haven't set anything to the Culture property of the DatePicker it is using the CurrentCulture of the CurrentThread. In other words the DatePicker should work correctly without setting the Culture to null. Please make sure you are not changing the culture somewhere else in the project.

Hope this helps.

Regards,
Kalin
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
cocowalla
Top achievements
Rank 1
answered on 22 Oct 2013, 02:41 PM
Ah, that was it! Someone had created a global style that set the culture to en-GB for all date pickers!
0
Kalin
Telerik team
answered on 22 Oct 2013, 03:12 PM
Hi Colin,

We are glad you have managed to resolve that.

If you have any other questions let us know.

Regards,
Kalin
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
DatePicker
Asked by
cocowalla
Top achievements
Rank 1
Answers by
cocowalla
Top achievements
Rank 1
Kalin
Telerik team
Share this question
or