I use DateTime.UtcNow.ToLongTimeString() to get the current time string.
However it behaves weird, sometimes it returns time like 3:10:00 and sometimes like 03:10:00 (leading zero). Why this happens?
I set a culture on application startup
Thread.CurrentThread.CurrentCulture = new CultureInfo(...);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(...);
And the different result for the time string comes from a Task (from what I can see now). So I create a Task and .Wait() for it to finish. Inside the task the time is converted to string differently.
UPDATE
For those who are interested, here is some helpful reading I found:
Is there a way of setting culture for a whole application? All current threads and new threads?
http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo.defaultthreadcurrentculture.aspx
You haven’t said anything about where this happens – but it could certain happen if you use different cultures. Normally without the leading zero I’d expect to see an am/pm designator as well though.
If you want consistent results, always specify the same culture (e.g.
CultureInfo.InvariantCulture).Of course, if this has all been on the same system without changing culture settings, that’s a different matter.