4

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).

Razack
  • 950
  • 3
  • 13
  • 26
  • Related: http://stackoverflow.com/q/468791/447156 ? – Soner Gönül Jul 21 '16 at 07:55
  • A `DateTime` just stores the number of 100ns intervals that have happened since midnight at the start of January 1st 0001. It doesn't remember *any* string or culture settings which may have been used in the process of constructing it. – Damien_The_Unbeliever Jul 21 '16 at 09:18
  • but when I am using above code with culture "ar" , the date become "16101437 10:12:20" (based on arabic calendar) – Razack Jul 21 '16 at 10:53

1 Answers1

2
CultureInfo cInfo = new CultureInfo("en-US");   
Thread.CurrentThread.CurrentCulture = cInfo;
Thread.CurrentThread.CurrentUICulture = cInfo;
Hitesh Thakor
  • 471
  • 2
  • 12