1. 修改时区的Windows API
// 针对于旧Windows系统,如Windows XP
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern int GetTimeZoneInformation(ref TimeZoneInformation lpTimeZoneInformation);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern bool SetTimeZoneInformation(ref TimeZoneInformation lpTimeZoneInformation);
// 针对于新Windows系统,如Windows 7, Windows8, Windows10
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern int GetDynamicTimeZoneInformation(ref DynamicTimeZoneInformation lpDynamicTimeZoneInformation);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern bool SetDynamicTimeZoneInformation(ref DynamicTimeZoneInformation lpDynamicTimeZoneInformation);
2. 相关结构struct类型
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
struct TimeZoneInformation
{
[MarshalAs(UnmanagedType.I4)]
internal int bias; // 以分钟为单位
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x20)]
internal string standardName; // 标准时间的名称
internal SystemTime standardDate;
[MarshalAs(UnmanagedType.I4)]
internal int standardBias; // 标准偏移
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 0x20)]
internal string daylightName; // 夏令时的名称
inter