DateTime.Parse is disabled for one hour. What for?

I am having trouble understanding why the value of the restored date time string is different from the original. I am writing a string in universal datetime (the format is "u", so it has a "z" at the end), but when it is restored, it differs by one hour. I use "u" to prevent this kind of thing. Can someone tell me why it is different?

I need a good string representation, because I will use the code in 5 different time zones.

Program:

using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            //Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfoByIetfLanguageTag("es-CR");

            DateTime min = DateTime.MinValue;

            Console.Write("Min value date: ");
            Console.WriteLine(min);

            Console.Write("String:         ");
            string str = min.ToString("u");
            Console.WriteLine(str);

            DateTime dt = DateTime.Parse(str);

            Console.Write("Restored Date:  ");
            Console.WriteLine(dt);

            Console.ReadLine();

        }
    }
}

Conclusion:

Date of minimum value: 01/01/0001 12:00:00 m.

String: 0001-01-01 00: 00: 00Z

Recovered date: 01/01/0001 01:00:00 m.

Edit: Option to try Costa Rican culture.

+3
2

DateTime, ? ToUniversalTime() ToLocalTime() . , "Z", .

+4

bytes.com.

, "Z" UTC CET.

CET ( ) UTC/GMT/ZULU/Military.

, .

+1

Source: https://habr.com/ru/post/1785237/


All Articles