Formatting DateTime - ignore culture

c#

Solution

Use `CultureInfo.InvariantCulture` as the culture or provider argument.

String.Format(CultureInfo.InvariantCulture, "{0:M-d-yyyy}", DateTime.Now)

Problem

I need to format a date to the following format: `M-d-yyyy` I tried using: `string.Format("{0:M-d-yyyy}", DateTime.Now)` But the output string will depend on the CurrentCulture on the computer where it's run, so sometimes the output might be `07/09/2014` or `07.09.2014` instead of `09-07-2014`. How can I easily prevent it from converting it based on the culture and treating it as a literal string?

Original source