Datetime localization using custom templates
I am working on localizing an application where custom templates are used to format datetime.
one example: dd-MM HH: mm
I need to get localized versions of this custom format for dates, so that I get the date using numbers and times, basically using a local ordering (dd MM or MM dd) and a local separator for date and time.
It's pretty trivial if I use the default formatting, but as soon as I deviate from them, the formatting becomes hardcoded.
Any ideas?
Thanks, Jonas
edit: I have CultureInfo objects, the problem is that when I do DateTime.ToString ("ES-es") I get too much information - I only need month + day, but by default ToString I get year + month + day
Edit again: I see how I can change the ShortDate pattern for every CultureInfo that I use. However, in some situations I also need the default ShortDate pattern, so a change that unfortunately would leave me with a different, equivalent problem.
Final edit: in case anyone cares. I never found a solution, so I ended up coded a static function that checks the current CultureInfo and returns a correctly formatted date, no year.
source to share
Perhaps you could try this:
DateTime.Now.ToString(new System.Globalization.CultureInfo(Thread.CurrentThread.CurrentCulture.Name));
If I want, for example, to display the time for a specific culture, I would do the following:
DateTime.Now.ToString(new System.Globalization.CultureInfo("ES-es"))
Cultureinfo acts like an IFormatProvider.
source to share