I've set, in my regional settings (for Czech, culture cs-CZ), the short time / long time pattern to following:
- Short time: H.mm
- Long time: H.mm.ss
I'm trying to use those settings in C# applications.
In following console app, everything works:
using System;
using System.Globalization;
class Program
{
static void Main()
{
Console.WriteLine(CultureInfo.CurrentCulture.Name);
Console.WriteLine(CultureInfo.CurrentCulture.DateTimeFormat.LongTimePattern);
Console.ReadLine();
}
}
The output is, as I thought, following:
cs-CZ
H.mm.ss
I've created ASP.NET application, which, to my uttermost surprise, doesn't reflect this.
Minimal example:
<%@ Page Language="C#" %>
<%= System.Globalization.CultureInfo.CurrentCulture.Name %><br />
<%= System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.LongTimePattern %>
Output:
cs-CZ
H:mm:ss
I've tried restarting, .NET2.0, .NET4.0, still no effect.
Note - This issue raised as a part of bug, where we forgot to include InvariantCulture for DateTime.ToString(), which should then be parsed by JSON deserializer. (The guy with this problem has somewhat different Time format separator).
Fixing the issue with re-creating CultureInfo isn't something I'm looking for, I just want to see the reason, as I wasn't able to reproduce the issue with any means.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…