SetSystemTime - UTC 或本地时间?

SetSystemTime - UTC or local time?

我从我的 C# 应用程序调用了 SetSystemTime。但是,如果我将 Windows 时区设置为与 UTC 的非零偏移量,似乎有时会调整系统时钟,就好像我提供的时间是 UTC(即转换为本地时间),而其他时间则不会” t,它只是将时间直接设置为date参数。

    [StructLayout(LayoutKind.Sequential)]
    internal struct SystemTime
    {
        public short Year;
        public short Month;
        public short DayOfWeek;
        public short Day;
        public short Hour;
        public short Minute;
        public short Second;
        public short Milliseconds;
    }

    [DllImport("kernel32.dll", SetLastError = true)]
    internal static extern bool SetSystemTime(ref SystemTime st);

    public static bool AdjustSystemClock(DateTime date)
    {
        SystemTime systemTime = new SystemTime();
        systemTime.Year = (short)date.Year;
        systemTime.Month = (short)date.Month;
        systemTime.Day = (short)date.Day;
        systemTime.Hour = (short)date.Hour;
        systemTime.Minute = (short)date.Minute;
        systemTime.Second = (short)date.Second;
        return SetSystemTime(ref systemTime);
    }

区别似乎是:当我使用 Windows 设置时区,然后启动应用程序时,当我调用 SetSystemTime() 时,它会调整提供的时间,就好像它是 UTC 一样。

但是当我使用 SetDynamicTimeZoneInformation() 函数设置时区时,重新启动应用程序然后调用 SetSystemTime() 然后它将时间直接设置为我提供的时间,而不管时区。

这是预期的行为吗?如何使两种设置时区的方法保持一致?

我相信我找到了问题所在。

原来写代码的人 SetDynamicTimeZoneInformation() 忽略了设置 Bias 属性.

因此设置的时区信息的 UTC 偏移量为零,因此不会进行任何调整。