I know how to specify cultures, date formats, time zones, etc...
My question here is when you just type DateTime.Now or DateTime.UtcNow in C#, is it using the culture from the web server your server-side code runs on, or is it using the client-side lang/culture of the web browser making the request?
To my great surprise, from my testing, it looks like this server code DateTime.Now is not using the web server's culture. But is actually using the client Lang/Cult inside the web browser!?
Is there anyway in the web.config to specify DateTime.Now/UtcNow to run in my web server's culture by default? I only want client cultures to be applied when I write code specifically for them.
DateTime.Now
and DateTime.UtcNow
don't have any culture at all. It's only when you format one as a string that it will use a culture... and which culture is used will depend on how you format it. To be clear in your code, just specify the culture explicitly, e.g.
string text = DateTime.UtcNow.ToString(CultureInfo.InvariantCulture);
However, DateTime.Now
will use the system-local time zone (i.e. the one on the server). That's orthogonal to the culture used for formatting.
See more on this question at Stackoverflow