Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep same date format after changing the language culture?

Date format is changing based on the culture when I am using DateTime.ParseExact() method.

I want to keep date in en-US culture always. Please see the below code I am using.

var date = DateTime.ParseExact("21072016 10:12:20", 
                               "ddMMyyyy HH:mm:ss", 
                               new CultureInfo("en-US",false));

string ff = date.ToString("yyyyMMddHHmmss");

When changing culture to ar it is converting date as in arabic calendar (16101437 10:12:20).

like image 664
Razack Avatar asked Oct 27 '25 14:10

Razack


1 Answers

CultureInfo cInfo = new CultureInfo("en-US");   
Thread.CurrentThread.CurrentCulture = cInfo;
Thread.CurrentThread.CurrentUICulture = cInfo;
like image 180
Hitesh Thakor Avatar answered Oct 29 '25 03:10

Hitesh Thakor



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!