问题描述
我正在尝试使用以下代码设置CurrentCulture的LongTimePattern属性:
I'm trying to set LongTimePattern property of CurrentCulture with the following code:
System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.LongTimePattern = "HH:mm:ss";
我收到InvalidOperationException:
实例是只读的。
and I'm getting InvalidOperationException:Instance is read-only.
任何想法如何改变?我想强制 LongTimePattern
显示任何文化的24h格式。
Any idea how can I change it? I want to force LongTimePattern
to show 24h format for any culture.
推荐答案
如果您更改System.Threading.Thread.CurrentThread.CurrentCulture,那么它将自动更新LongTimePattern。
If you change the System.Threading.Thread.CurrentThread.CurrentCulture then it will automatically update the LongTimePattern.
您不能在当前分配的文化信息中进行任何更新,但创建一个新的,并将其分配给当前的文化。
You can't make any updation in current assigned culture info but create a new one and assign it to current culture.
System.Globalization.CultureInfo c = new System.Globalization.CultureInfo("es-ES");
c.DateTimeFormat.LongTimePattern = "h-mm-ss";
Thread.CurrentThread.CurrentCulture = c;
这篇关于CurrentCulture.DateTimeFormat.LongTimePattern只读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!