This project has moved. For the latest updates, please go here.

How can I use the TimeSpan2FormatInfo.CurrentInfo.Format thread independent

Jun 25 at 11:25 AM
Edited Jun 25 at 11:26 AM
Sorry for a possible stupid question, but I have started writng simple apps 4 weeks ago after 10 Years of abstinence.

Your TimeSpan2FormatInfo works fine, if I don't want to change it on the fly.

But how I can I change the result with a given culture.

To explain it a bit more, that works:

var result = TimeSpan2FormatInfo.CurrentInfo.Format("f", timeSpan, CultureInfo.CurrentCulture);

And that doesn't:
CultureInfo testCulture = CultureInfo.CreateSpecificCulture("en-US");
var result = TimeSpan2FormatInfo.CurrentInfo.Format("f", timeSpan, testCulture);

It seems to me, you are not using the IFormatProvider.

Here is the part from your code, why I'm thinking it isn't using it:
    public static TimeSpan2FormatInfo CurrentInfo
    {
        get
        {
            var currentCulture = Thread.CurrentThread.CurrentUICulture;
            return GetInstance(currentCulture);
        }
    }
The only way I have found so far is to change the thread culture.

Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");

That works, but it is not so nice.

Is there another way, which I might have overseen?

/Sascha