I have this:
DateTime date = new DateTime();
and i then print it. Here are the results:
Localhost:
date: 1/1/0001 12:00:00 AM
On server:
date: 1-1-0001 0:00:00
The correct way is the one on localhost. How to fix this and why is this happening? It’s the same code.
Because of different regional setting on different machines. To have date time output in the same format you ahve to specify format string explciitly:
Also as John recommeded in comments below if you want having date time output in the same format on different machines despite local regional settings you can use InvariantCulture format provider:
MSDN:
MSDN: