I need to display some dates on windows phone with day and month only.
For example, January 1st, for American users I want the text to be ‘1/31′ and for UK users I want it to be ’31/1’.
What’s the easiest way to achieve something like this?
UPDATE:
My app will be available in a lot of countries. Do I have to specify each culture to get what I want?
For example,
de-DE Culture 01.10
en-US Culture 10/1
es-ES Culture 01/10
fr-FR Culture 01/10
The left column contains some countries my app will support, the right column is how I want my date text to be.
Is there any generic way I can achieve this?
Wow, that question is particularly interesting! I didn’t found some obvious solution, so here it goes:
If you can’t use
DateTimeFormatInfo, then following code should do the trick:As @ken2k correctly mentioned, this solution is also flawed (and much more than I actually expected). Here is the complere test suite (compile as console application):
Further optimization is possible (at least in full framework), however it’s becoming rather complex (limited framework of a Windows Phone adds complexity also) and it’s not clear if such date representation will make sense in some cultures. For example in some cultures date part separator is a two-char sequence:
does
08. 14actually look good? Or should it be08. 14.? I’m not sure. If I were you, and I really want to handle maximum amount of cultures, I would just stick with standard “d” format specifier.