This project has moved and is read-only. For the latest updates, please go here.

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

Jun 25, 2017 at 12:25 PM
Edited Jun 25, 2017 at 12:26 PM
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
            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?