3
The method Convert.ChangeType
is converting the date the wrong way I hope 24/02/2015
and comes 23/02/2015
. Does anyone know why?
Code example:
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();
}
}
}
You wait 24/02/2015 and is returning 24/02/2015, it’s not right?
– stderr
Fixed. Sorry I’m at work I made it running.
– Reiksiel
You’re right: https://dotnetfiddle.net/3Fd28k
– Maniero
@bigown, I edited the question to show the result of my console. Have any idea?
– Reiksiel
For the time being, I switched to test other cultures but it’s still ok. It’s likely you have something with your environment. I doubt that a different version of . Net is producing different results. https://dotnetfiddle.net/8bfSTH
– Maniero
I found this format in Nfe XML. Unfortunately I can’t find more date examples in this format. There is a standard format for XML date?
– Reiksiel
Not that I know, in theory each one can create the format you want. It has a format for the XML definition. But the problem is not format, it seems to be ok, so much so that I showed it works. I would need to figure out why yours . Net is not doing the same.
– Maniero
Let’s go continue this discussion in chat.
– Reiksiel