1

I am working on localization for an app where custom patterns are used to format the date-time.

one example is: 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 the time, basically using the local order (dd MM or MM dd) and the local seperator for both date and time.

This is fairly trivial, as long as I am using the default formatting, but as soon as I stray from these, the formatting becomes hardcoded.

Any ideas?

Thanks, Jonas

edit: I have the cultureInfo objects, the problem is that when I do a DateTime.ToString("ES-es"), I get too much info - I need only month+day, but with the default ToString, I get year+month+day

Edit again: I see how I can change the ShortDate pattern for each CultureInfo object I use. However, I also need the default ShortDate pattern in some situations, so changing that would, unfortunately, leave me with another, equivalent problem.

Final edit: in case anyone cares. I never did find a solution, so I ended up coding a static function that checks the current CultureInfo, and returns the correctly formatted date, sans year.

1
  • I have the cultureInfo objects, the problem is that when I do a DateTime.ToString("ES-es"), I get too much info - I need only month+day, but with the default ToString, I get year+month+day. Commented Nov 24, 2008 at 10:14

3 Answers 3

4

Look at the DateTimeFormatInfo class (CultureInfo.DateTimeFormat property), in particular the properties DateSeparator, TimeSeparator, ShortDatePattern.

Sign up to request clarification or add additional context in comments.

Comments

2

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 particular culture, i would do this:

DateTime.Now.ToString(new System.Globalization.CultureInfo("ES-es"))

The cultureinfo acts as the IFormatProvider.

1 Comment

DateTime.Now.ToString("dd-MMM-yy", new System.Globalization.CultureInfo("es-CO")) -- this is an example including format.
-1

The CultureInfo class would be a good place to start looking.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.