I had a quick date formatting function, here it is:
public static string archiveServerDateTime(string datetime)
{
DateTime tempDateTime = DateTime.ParseExact(datetime,"dd.MM.yyyy HH:mm:ss", null);
return tempDateTime.ToString("yyyy/MM/dd:HH:mm:ss");
}
to find the result of the function = 2009.10.22: 16: 21: 03, and it is surprising that this is only on 1 production server, the test server worked perfectly ...
So now I rewrote the function in the old school style:
public static string archiveServerDateTime(string datetime)
{
DateTime tempDateTime = DateTime.ParseExact(datetime,"dd.MM.yyyy HH:mm:ss", null);
string yearPart = Convert.ToString(tempDateTime.Year);
string monthPart = Convert.ToString(tempDateTime.Month).PadLeft(2,'0');
string dayPart = Convert.ToString(tempDateTime.Day ).PadLeft(2, '0');
string hourPart = Convert.ToString(tempDateTime.Hour).PadLeft(2, '0');
string minutePart = Convert.ToString(tempDateTime.Minute).PadLeft(2, '0');
string secondPart = Convert.ToString(tempDateTime.Second).PadLeft(2,'0');
return yearPart + @"/" + monthPart + @"/" + dayPart + ":" + hourPart + ":" + minutePart + ":" + secondPart;
}
So, I ask you, ladies and gentlemen, have I replaced completely good code, or is this a Microsoft bug? Can we really trust these new language features, which apparently aren't that strong, or am I just missing something?
source
share