I have the following code
DateTime.Now.ToString("MM/dd/yyyy")
It always gives me this output : "04.13.2011" instead of "04/13/2011". May I know why I am getting this weird issue?
DateSeparator is the character used by various date/time conversion routines as the character that separates the day from the month and the month from the year in a date notation. It is used by the date formatting routines.
In an Excel sheet, select the cells you want to format. Press Ctrl+1 to open the Format Cells dialog. On the Number tab, select Custom from the Category list and type the date format you want in the Type box. Click OK to save the changes.
MMM/DD/YYYY. Three-letter abbreviation of the month, separator, two-digit day, separator, four-digit year (example: JUL/25/2003) YY/DDD. Last two digits of year, separator, three-digit Julian day (example: 99/349)
Try this
DateTime.Now.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture)
You're almost certainly in a culture where that's the default date separator. If you want to force /
you can quote it in the format string:
string x = DateTime.Now.ToString("MM'/'dd'/'yyyy")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With