Why does DisplayFormat with DataFormatString changes “/” (slash) to “-” (dash)?

ε祈祈猫儿з 提交于 2019-11-30 08:34:45

Use DataFormatString = @"{0:dd\/MM\/yyyy}" instead. Since the / identifies a character that should be replaced by the default date separator for the current culture, you need to escape it in order for it to be used as a literal in the format.

This way you have a fixed format instead of one that dynamically uses the date separator of the current culture.

An alternative to escape the / character can be: DataFormatString = "{0:dd'/'MM'/'yyyy}"

Change the Short date format of the server' Regional settings to use slashes e.g. yyyy/MM/dd.
This solved the issue for me.

Can you change it to DataFormatString = "{0:d}"

That should give you the short date pattern of mm/dd/year

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!