How to convert a Datetime string to a current culture datetime string

前端 未结 6 644
庸人自扰
庸人自扰 2020-12-03 06:41

I have string say \"12/1/2011\" in English US culture my current machine culture is English Uk which is \"dd/mm/yyyy\" format. How to convert the 12/1/2011 to 1/12/2011. I h

6条回答
  •  广开言路
    2020-12-03 07:15

    DateTimeFormatInfo usDtfi = new CultureInfo("en-US", false).DateTimeFormat;
    DateTimeFormatInfo ukDtfi = new CultureInfo("en-GB", false).DateTimeFormat;
    string result = Convert.ToDateTime("12/01/2011", usDtfi).ToString(ukDtfi.ShortDatePattern);
    

    This will do the trick ^^

提交回复
热议问题