How to make datetime.now return date in UK format with c#

I want datetime.now to return the datetime object in UK format. It does so on my local computer but when I upload the code to the server it does it in US format

Jon Skeet
people
quotationmark

I want datetime.now to return the datetime object in UK format.

There's no such concept, any more than an int is a value "in hex" or "in decimal". A DateTime is just a DateTime - you can specify the format when you convert it to a string. It's really important to understand the difference between an inherent value, and what it looks like after it's converted to text - very few types are aware of a custom, modifiable format to use when converting themselves - it's either provided externally (as for DateTime, numbers etc) or simply fixed.

Before you convert start hard-coding a UK format though, I would strongly advise you to consider exactly what you're doing:

  • Ideally, avoid the conversion in the first place. A lot of the time, string conversions are unnecessary and can be problematic.
  • Is the text going to be consumed by another machine? Use an ISO-8601 standard format.
  • Is the text going to be consumed by a person? Use their culture rather than some arbitrary one you decide on.
    • ... Or display it in a dedicated control...

people

See more on this question at Stackoverflow