You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

全球化问题:系统语言非英文时如何转换TimeZone.CurrentTimeZone.StandardName为英文?

Fix for Getting English Time Zone Standard Name in Non-English Systems

Got it, let's tackle this issue. The problem with TimeZone.CurrentTimeZone.StandardName not respecting your CurrentUICulture setting is actually tied to how that old API works—let me break this down and give you actionable fixes.

First, why the CurrentUICulture switch doesn't help:

The legacy TimeZone class pulls the standard name directly from the system's localized timezone database, which is tied to the system's default language/region settings—not the thread's CurrentUICulture. Changing CurrentUICulture won't override this because this API wasn't designed to respect runtime culture switches for timezone names.

The TimeZoneInfo class replaces the outdated TimeZone and offers proper globalization support for timezone names. Here's how to get the English standard name:

  1. Grab the local timezone's TimeZoneInfo instance
  2. Use GetDisplayName() with the English culture explicitly specified
using System;
using System.Globalization;

public static string GetEnglishTimeZoneStandardName()
{
    var localZone = TimeZoneInfo.Local;
    var enUsCulture = CultureInfo.GetCultureInfo("en-US");
    
    // Get the standard name in English
    return localZone.GetDisplayName(
        TimeZoneInfoDisplayType.StandardName,
        enUsCulture
    );
}

Compatibility with Legacy TimeZone Code

If you're stuck maintaining code that uses TimeZone and can't switch to TimeZoneInfo entirely, you can map the old TimeZone to its TimeZoneInfo equivalent and fetch the English name that way:

var oldTimeZone = TimeZone.CurrentTimeZone;
var correspondingZone = TimeZoneInfo.FindSystemTimeZoneById(oldTimeZone.Id);
var enUsCulture = CultureInfo.GetCultureInfo("en-US");

string englishStandardName = correspondingZone.GetDisplayName(
    TimeZoneInfoDisplayType.StandardName,
    enUsCulture
);

Key Notes

  • This works across .NET Framework, .NET Core, and .NET 5+
  • Most modern OSes (Windows, Linux, macOS) include multi-language timezone metadata by default, so you won't need extra installations
  • Avoid relying on TimeZone for new development—it's marked as obsolete in .NET 6+ due to limited globalization support

内容的提问来源于stack exchange,提问作者yBother

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 07:23:47