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

如何在Windows 10中通过编程方式修改区域时间格式

程序化修改Windows 10区域时间格式的持久化问题

尝试通过代码修改Windows 10区域时间格式时,使用intl.cpl搭配XML文件的方式仅对当前用户生效,注销重新登录后设置无法保留;但通过Windows UI修改则能正常持久化。

当前使用的XML配置

<gs:GlobalizationServices xmlns:gs="urn:longhornGlobalizationUnattend">
<gs:UserList><gs:User UserID="Current" CopySettingsToDefaultUserAcct="true" CopySettingsToSystemAcct="true"/>
</gs:UserList>
<gs:UserLocale><gs:Locale Name="en-GB" SetAsCurrent="true" ResetAllSettings="false"/></gs:UserLocale>
</gs:GlobalizationServices>

持久化解决方案

1. 完善XML配置文件

补充系统级区域设置和时间格式配置,确保修改覆盖当前用户、默认用户及系统账户:

<gs:GlobalizationServices xmlns:gs="urn:longhornGlobalizationUnattend">
    <gs:UserList>
        <gs:User UserID="Current" CopySettingsToDefaultUserAcct="true" CopySettingsToSystemAcct="true"/>
    </gs:UserList>
    <gs:UserLocale>
        <gs:Locale Name="en-GB" SetAsCurrent="true" ResetAllSettings="false"/>
    </gs:UserLocale>
    <!-- 新增系统区域配置,确保全局生效 -->
    <gs:SystemLocale>
        <gs:Locale Name="en-GB"/>
    </gs:SystemLocale>
    <!-- 明确指定时间格式(匹配en-GB标准) -->
    <gs:TimeFormat>
        <gs:LongTimeFormat>HH:mm:ss</gs:LongTimeFormat>
        <gs:ShortTimeFormat>HH:mm</gs:ShortTimeFormat>
    </gs:TimeFormat>
    <gs:Calendar>
        <gs:CalendarPreference>Gregorian</gs:CalendarPreference>
    </gs:Calendar>
</gs:GlobalizationServices>

2. 管理员权限下执行PowerShell命令

通过PowerShell直接调用系统API完成配置导入和同步,确保设置持久化:

# 替换为你的XML文件实际路径
$xmlConfigPath = "C:\temp\globalization_config.xml"

# 导入XML配置
control intl.cpl,,/f:"$xmlConfigPath"

# 强制更新系统区域、用户语言列表和归属地
Set-WinSystemLocale -Locale en-GB
Set-WinUserLanguageList -LanguageList (Get-WinUserLanguageList) -Force
Set-WinHomeLocation -GeoId 242  # GeoID 242对应英国地区

# 重启资源管理器让设置即时生效(可选)
Stop-Process -Name explorer -Force

关键注意事项

  • 必须以管理员身份运行PowerShell,否则无法修改系统账户和默认用户的配置
  • SystemLocale节点是实现注销后设置保留的核心,它负责同步系统级别的区域格式
  • 结合Set-WinSystemLocale等命令直接修改底层设置,比仅依赖intl.cpl导入更可靠

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 00:08:18