How do I set the format of dates to default to that of the device the software is running on?
This is a constant problem across all Microsoft technologies. You'd think that by now, they'd have realised that if the person using the software lives in Australia, they probably want to see dates in Australian format.
THIS IS NOT THE ANSWER
New question opened here because I can't unmark this as the answer:
https://forums.xamarin.com/discussion/100542/set-default-date-format-to-date-format-from-device-culture
This looked like it would work but it does absolutely nothing:
CultureInfo.DefaultThreadCurrentCulture = new CultureInfo(CultureInfo.CurrentUICulture.ToString());
I pieced it together from @N_Baua 's post. Several of the other posts' code don't work, although TwoLetterISOLanguageName only has 'en' while CultureInfo.CurrentUICulture.ToString() has the full culture string. It's still really dumb that we have to add this line of code to our apps. Why is it necessary? The culture should default to the culture of the regional settings without having to do this.
The bug has been confirmed:
https://bugzilla.xamarin.com/show_bug.cgi?id=58635
Answers
@MelbourneDeveloper ,
The MS guyss knew such issues were to come. so they had Formatting Date and Time for a Specific Culture
You need to detect the user culture and you're done.
Hope this helps.
N Baua
I think you have to take a look to DateTime format
And define the "Culture" (I think, by default, the Culture is the "DEVICE CULTURE")
https://msdn.microsoft.com/it-it/library/8kb3ddd4(v=vs.110).aspx
https://forums.xamarin.com/discussion/85013/default-datepicker-format
@DirkWilhelm ,
Man you read that little tag too, classy, I've learnt a new dimension on forum. Kudos man, 1 like from me.
@N_Baua actually i simply googled for "xamarin.forms datepicker culture" and picked that thread from the results
I haven't thought that, plus I only read the query, not the tags many times. So this is a lesson for me.
These answers don't work, but even if they did, these answers give half of the answer. I.e. they tell you how to set the current culture. But, I can't see anything here on how to retrieve the current culture of the device. So, I'll add a new question.
How do you get the current culture for the device's regional settings?
The answers marked as correct in the other threads don't work. I just get a compilation error.
'CultureInfo' does not contain a definition for 'DefaultThreadCultureInfo'
@MelbourneDeveloper ,
The above should work
and if you decide to change (dynamically)
Hope this solves your concern,
Regards,
N Baua
Please see this thread and comment here to request that Xamarin make this the default behavior for all apps. I.e. all apps should default to the culture of the device:
https://forums.xamarin.com/discussion/100540/set-default-culture-to-culture-of-device
THIS IS NOT THE ANSWER
New question opened here because I can't unmark this as the answer:
https://forums.xamarin.com/discussion/100542/set-default-date-format-to-date-format-from-device-culture
This looked like it would work but it does absolutely nothing:
I pieced it together from @N_Baua 's post. Several of the other posts' code don't work, although TwoLetterISOLanguageName only has 'en' while CultureInfo.CurrentUICulture.ToString() has the full culture string. It's still really dumb that we have to add this line of code to our apps. Why is it necessary? The culture should default to the culture of the regional settings without having to do this.
Actually, false alarm. This did absolutely nothing. Dates are still displayed in USA format.
@N_Baua , @DirkWilhelm , @AlessandroCaliaro the problem is actually very different to what I first thought. I have documented up a bug. You can see the problem here:
https://forums.xamarin.com/discussion/comment/290295/#Comment_290295
The bug has been confirmed:
https://bugzilla.xamarin.com/show_bug.cgi?id=58635
And at the end of 2019 it is still a bug - the bugzilla link above is now out of date but has some interesting comments on it
in case the bugzilla archive vanishes, the original frustrated fellow-Aussie moved the bug to github https://github.com/xamarin/Xamarin.Forms/issues/2049