Below is my code.
static void Main(string[] args)
{
DateTime dt = DateTime.Now;
Console.WriteLine(dt.ToString("dd/MMM/yyyy HH:mm:ss"));
Console.Read();
}
When we execute the above code in the Visual Studio Community Edition (16.9.4) then it returns 25-Apr-2021 21.35.02 instead of 25/Apr/2021 21:35:02
If we execute the same code in the Visual Studio Professional Version (16.9.4) then it works fine. It always returns 25/Apr/2021 21:35:02.
This issue happens with all project types like .net5, Core 3.1, .net standard framework, .net 4.5 (console, web, Xamarin, WPF AND Desktop Application).
Can someone guide on how to resolve this issue in the VS Community Edition?
If you use
/
you are using the custom format specifier / which does: replace it with the current culture's date-separator, which seems to be-
in your case.You have two options to prevent it, pass
InvariantCulture
:Escape the format specifier by wrapping it in ticks
'
: