Search code examples
c#datetimestring-to-datetime

Convert from fr-CA time to US time format


I have a string datetime like this in fr-CA time : "16 août 1980".

How can i change this string to US time like "16 aug 1980" or "august 16 1980" using c#?

I need create a cultureinfo of this time?


Solution

  • Yes, you need to specifiy the cultureInfo. In this case, you can use DateTime.ParseExact like so :

    var myDate = "16 août 1980";
    var dateConverted = DateTime.ParseExact(myDate, "D", CultureInfo.GetCultureInfo("fr-CA"));
    var dateUs = dateConverted.ToString("MMMM dd, yyyy", CultureInfo.GetCultureInfo("en-US"));