Today I got a really strange problem.
Try to execute this C# code:
class Program
{
static void Main(string[] args)
{
string yesterdayString = (DateTime.Now - TimeSpan.FromDays(1)).ToString("R");
string nowString = DateTime.Now.ToString("R");
DateTime.Parse(yesterdayString);
DateTime.Parse(nowString);
DateTime.Parse("Wed, 29 Feb 2012 18:05:49 GMT"); // this is what i have in yesterdayString
DateTime.Parse("Thu, 01 Mar 2012 18:05:40 GMT"); // this is what i have in nowString
}
}
Of course you will get the problem just for today. I've added the last two commands to let you know what the problem is. Tomorrow and throughout the month of March DateTime.Parse will throw a FormatException (String was not recognized as a valid DateTime.)
Why?
I would say you found a bug. This should work:
//
var spanish = CultureInfo.GetCultureInfo("es");
var date = DateTime.Parse(DateTime.Now.ToString("R", spanish), spanish);
or for Italian it still throws...
var italian = CultureInfo.GetCultureInfo("it");
var date = DateTime.Parse(DateTime.Now.ToString("R", italian), italian);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With