Search code examples
c#asp.netdateglobalizationdatetime-format

DateTime.Now.ToUniversalTime() Has the Wrong Year


And Idea Why the Year appears as 2555?

enter image description here

The culture of the site is Thai


Solution

  • Yes - any time DateTime is converted to a string with no explicit culture specified, it will use the current culture's calendar system. However, the DateTime components themselves still reflect the Gregorian calendar.

    You'll see the 2555 if you use:

    int thaiYear = new ThaiBuddhistCalendar().GetYear(DateTime.Now);
    

    Basically, if you want to get culture-specific date information programmatically, you need to use a System.Globalization.Calendar. When formatting a date, make sure you specify the right culture for the calendar you want to use.