I have dd-MM-yyyy date pattern for my windows machine. In below code I'm trying to get date format through C# code, but it's giving me M/d/yyy instead of dd-MM-yyyy. In code is correct ?
Console.WriteLine(DateTime.Now);
Console.WriteLine(CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern);

Use CurrentCulture instead of CurrentUICulture`.
CultureInfo.CurrentCulture.DateTimeFormat.ShortDatePattern
CurrentCulture is for formatting of numbers and dates.
CurrentUICulture for localisation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With