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();
}
}
}