Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting date "day dd/mm/yyyy"

I'm trying to format a date to look this way: "day mm/dd/yyyy" for that I'm using something like : "dddd, " + dateFormatInfo.ShortDatePattern The thing is ShortDatePattern does seem to be specific to the current culture info. for example I'm getting: fr_FR : Lundi 27/06/2011 gb_GB : Monday 27/06/2011 when it should be Monday 06/27/2011 I hope I'm being clear.

[Update] I wanted the string to update automatically between "dd/mm/yyyy" and "mm/dd/yyyy" depending on the current culture and i thought ShortDatePattern didn't do the trick but it actually does! it's just that in en_GB it's still "dd/mm/yyyy" [/update]

[Resolved]
DateTime date;
date.ToString("dddd, " + CurrentCultureInfo.DateTimeFormat.ShortDatePattern);

like image 394
Aghilas Avatar asked Jun 27 '11 11:06

Aghilas


People also ask

How do you format date that is in the format dd mm yyyy?

First, pick the cells that contain dates, then right-click and select Format Cells. Select Custom in the Number Tab, then type 'dd-mmm-yyyy' in the Type text box, then click okay. It will format the dates you specify.

How can change date format in dd mm yyyy in HTML?

To set and get the input type date in dd-mm-yyyy format we will use <input> type attribute. The <input> type attribute is used to define a date picker or control field. In this attribute, you can set the range from which day-month-year to which day-month-year date can be selected from.

Which format is used to display the date and day?

Overview of date and time formats The dates appear as, mm/dd/yyyy in the U.S. and as, dd/mm/yyyy outside the U.S. where mm is the month, dd is the day, and yyyy is the year. The time is displayed as, hh:mm:ss AM/PM, where hh is the hour, mm is minutes, and ss is seconds.

How do you format a date?

Press CTRL+1. In the Format Cells box, click the Number tab. In the Category list, click Date, and then choose a date format you want in Type.


2 Answers

If you always want the date pattern to be MM/dd/yyyy, then specify that:

string format = "dddd, MM/dd/yyyy";

Note that the "/" part is also locale-specific; if you want it to always be a forward-slash, you should escape it:

string format = "dddd, MM'/'dd'/'yyyy";

If that's not what you were looking for, please update your question to make it clear exactly what you're doing (with sample code), the result you're getting, and the result you want.

like image 120
Jon Skeet Avatar answered Oct 05 '22 23:10

Jon Skeet


You can use the following:

DateTime date;
date.ToString("dddd, MM/dd/yyyy");
like image 45
Chris Snowden Avatar answered Oct 05 '22 22:10

Chris Snowden