Convert.ChangeType converts data wrongly

3

The method Convert.ChangeType is converting the date in the wrong way I expect 24/02/2015 and comes 23/02/2015 . Does anyone know why?

Code sample:

using System;
using System.Globalization;

namespace ConsoleApplication4
{
    public class Program
    {
        public static void Main(string[] args)
        {
            string data = @"2015-02-24T01:00:01-01:00";

            Console.WriteLine(DateTime.ParseExact(data, "yyyy-MM-ddTHH:mm:sszzz", CultureInfo.InvariantCulture));//CONVERTE ERRADO
            Console.WriteLine(DateTime.Parse(data));//CONVERTE ERRADO


            Console.WriteLine((DateTime?)Convert.ChangeType(data, Nullable.GetUnderlyingType(typeof(DateTime?))));//CONVERT ERRADO
            Console.WriteLine((DateTime)Convert.ChangeType(data, typeof(DateTime)));//CONVERT ERRADO

            Console.ReadLine();

        }
    }
}

    
asked by anonymous 16.03.2015 / 17:56

1 answer

0

I found it!

Next date comes with this part: -01:00 that means timezone. When we convert a date it adapts to the timezone of the PC.

The program converted to the value: 24/02/2015 01:00:01 in timezone -1, in my case, I'm in SP and timezone is -3 it subtracts 2h and gets the value 23/02/2015 23:00:01 .

    
16.03.2015 / 19:24