Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date separator issue

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?

like image 869
Rocky Singh Avatar asked Apr 12 '11 20:04

Rocky Singh


People also ask

What is date separator?

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.

How do I change the date separator in Excel?

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.

What is format mmm dd yyyy?

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)


2 Answers

Try this

DateTime.Now.ToString("MM/dd/yyyy", CultureInfo.InvariantCulture)
like image 176
Rikin Patel Avatar answered Oct 21 '22 09:10

Rikin Patel


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")
like image 25
Jon Skeet Avatar answered Oct 21 '22 10:10

Jon Skeet