Monday, September 29, 2025

c# - How to solve problem with convension date into string with char "/" in format mask

This result can be obtained when trying to convert a date to a string using a format mask containing the character '/'.
DateTime dt = DateTime.Now;
MessageBox.Show( dt.ToString( "yyyy/MM/dd", CultureInfo.GetCultureInfo( "de-DE" ) ) );
Output:
2025.09.29
The solution is to change the Culture:
DateTime dt = DateTime.Now;
MessageBox.Show( dt.ToString( "yyyy/MM/dd", CultureInfo.GetCultureInfo( "en-US" ) ) );
Output:
2025/09/29

No comments:

Post a Comment