Wednesday, April 2, 2008

Standard Date and Time Format Strings

For the ease of some pain in the arse... :)

DateTime theDate = DateTime.Now;
string result, showTodays;
result = theDate.ToString("dddd");
CultureInfo culture = new CultureInfo("pt-BR");
showTodays = theDate.ToString("G", culture);
lblDateToday.Text = result;
lblShowDate.Text = showTodays;


What else in.... theDate.ToString("XXXX");

Use ToString(String) and the current thread culture.

Culture: English (United States)

(d) Short date: . . . . . . . 4/17/2006
(D) Long date:. . . . . . . . Monday, April 17, 2006
(t) Short time: . . . . . . . 2:22 PM
(T) Long time:. . . . . . . . 2:22:48 PM
(f) Full date/short time: . . Monday, April 17, 2006 2:22 PM
(F) Full date/long time:. . . Monday, April 17, 2006 2:22:48 PM
(g) General date/short time:. 4/17/2006 2:22 PM
(G) General date/long time (default):
. . . . . . . . . . . . . 4/17/2006 2:22:48 PM
(M) Month:. . . . . . . . . . April 17
(R) RFC1123:. . . . . . . . . Mon, 17 Apr 2006 21:22:48 GMT
(s) Sortable: . . . . . . . . 2006-04-17T14:22:48
(u) Universal sortable (invariant):
. . . . . . . . . . . . . 2006-04-17 21:22:48Z
(U) Universal full date/time: Monday, April 17, 2006 9:22:48 PM
(Y) Year: . . . . . . . . . . April, 2006
(o) Roundtrip (local):. . . . 2006-04-17T14:22:48.2698750-07:00
(o) Roundtrip (UTC):. . . . . 2006-04-17T21:22:48.2698750Z
(o) Roundtrip (Unspecified):. 2000-03-20T13:02:03.0000000


more [msdn]

0 comments: