DateTime ToString(“dd/MM/yyyy”) returns dd.MM.yyyy

前端 未结 4 2076
刺人心
刺人心 2020-12-25 08:12

I have also tried shielding the \'/\' symbol in the formatting string, but it didn\'t quite work. My final goal is to get the date with the \'/\' symbols as separators. I g

4条回答
  •  别那么骄傲
    2020-12-25 08:40

    This is because of the way ToString works by default, in accordance with the current culture:

    This method uses formatting information derived from the current culture.

    So, override that:

    string date = dt.ToString("dd/M/yyyy", CultureInfo.InvariantCulture)
    

提交回复
热议问题