C#冬令时夏令时判断

using System.Text;

namespace ConsoleApp5
{
    internal class Program
    {
        static void Main(string[] args)
        {
            var tzi = TimeZoneInfo.FindSystemTimeZoneById("W. Europe Standard Time");
            var localDate = TimeZoneInfo.ConvertTime(DateTime.Parse("2022-01-01T00:00:00.000Z"), tzi);
            var fiveYear = DateTime.Parse("2025-01-01");
            var tipLast = "";
            var stb = new StringBuilder();
            while (localDate < fiveYear)
            {
                var tip = tzi.IsDaylightSavingTime(localDate) ? "夏令时" : "冬令时";
                if (tipLast != tip)
                {
                    stb.Append($"{tip}:{(localDate.ToString("yyyy-MM-ddTHH:mm:ssZ"))}\r\n");
                    tipLast = tip;
                }

                localDate = localDate.AddHours(1);
            }
           
            Console.WriteLine( stb.ToString() );
        }
    }
}

C#冬令时夏令时判断_第1张图片

你可能感兴趣的:(工具,ASP.NET,Core,c#,java,前端)