Given the following C# code:
var dt = DateTime.Now;
Console.WriteLine("{0:MM/dd/yy} ... {1}", dt, string.Format("{0:MM/dd/yy}", dt));
... when the short date (under Windows 7, Control Panel -> Region and Language -> Additonal Settings -> Date
) is set to the USA standard of "M/d/yyyy
," I get this:
06/17/14 ... 06/17/14
However, when I change the short date to "ddd dd MMM yyyy
," I get this:
06/17/14 ... 06 17 14
I was under the impression that Console.WriteLine
and string.Format
always string formatted DateTime
values identically. What is the explanation for this discrepancy?
EDIT: Looks like this happens only in standard unit test output (Visual Studio), which is where I originally saw the problem. When the code executes in a console app, the output is 06 17 14 ... 06 17 14
.
Console.WriteLine
andString.Format
. – Tegan06 17 14 ... 06 17 14
. I'm using Win 7 and did the test from .net framework 2.0 to 4.5.1 – Titanite06 17 14 ... 06 17 14
. The output from my original project was written from a unit test, though (standard, usingMicrosoft.VisualStudio.TestTools.UnitTesting
), so I created a new unit test project, and voila, the output from the unit test read06/17/14 ... 06 17 14
. Can someone please try this and let me know whether you get different output? – Roughrider