小编Aym*_*rki的帖子

有没有办法检查它是否是UTC的夏令时(夏令时)?

有没有办法检查它是否是UTC的夏令时(夏令时),而不使用转换

我不想使用转换,因为它在2月28日凌晨2点是模棱两可的.这个:

using System;

namespace Rextester
{
    public class Program
    {
        public static void PrintSeasonKindTime(DateTime utcDate)
        {
            // Convert dt to Romance Standard Time
            TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time");
            DateTime localDate = TimeZoneInfo.ConvertTime(utcDate, tzi);

            Console.WriteLine("Local date: " + localDate.ToString("yyyy.MM.d HH:mm:ss") +  (tzi.IsDaylightSavingTime(localDate) ? " is summer" : " is winter"));
        }

        public static void Main(string[] args)
        {
            DateTime currentUTCDateTime = new DateTime(2018,10,27,23,59,0, DateTimeKind.Utc);
            double nbMinutes = 1.0;

            PrintSeasonKindTime(currentUTCDateTime);
            PrintSeasonKindTime(currentUTCDateTime.AddMinutes(nbMinutes));
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

会显示这个:

Local date: 2018.10.28 …
Run Code Online (Sandbox Code Playgroud)

c# utc dst

2
推荐指数
1
解决办法
1484
查看次数

标签 统计

c# ×1

dst ×1

utc ×1