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

前端 未结 6 642
庸人自扰
庸人自扰 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:14

    This works for me:

    string myTime = DateTime.Parse("12/1/2011")
                            .ToString(CultureInfo.GetCultureInfo("en-GB").DateTimeFormat.ShortDatePattern);
    

提交回复
热议问题