Formatting Dates, Times and Numbers in ASP.NET
Format Description | Code Snippet | Output |
---|---|---|
Short date pattern (d) | DateTime.Now.ToString("d") | 11/8/2010 |
Long date pattern (D) | DateTime.Now.ToString("D") | Monday, November 08, 2010 |
Full date/time pattern - short time (f) | DateTime.Now.ToString("f") | Monday, November 08, 2010 3:39 PM |
Full date/time pattern - long time (F) | DateTime.Now.ToString("F") | Monday, November 08, 2010 3:39:46 PM |
General date/time pattern - short time (g) | DateTime.Now.ToString("g") | 11/8/2010 3:39 PM |
General date/time pattern - long time (G) | DateTime.Now.ToString("G") | 11/8/2010 3:39:46 PM |
Month/day pattern (M) | DateTime.Now.ToString("M") | November 08 |
Round-trip date/time pattern (O) | DateTime.Now.ToString("O") | 2010-11-08T15:39:46.4804000-08:00 |
RFC 1123 pattern (R) | DateTime.Now.ToString("R") | Mon, 08 Nov 2010 15:39:46 GMT |
Sortable date/time pattern (s) | DateTime.Now.ToString("s") | 2010-11-08T15:39:46 |
Short time pattern (t) | DateTime.Now.ToString("t") | 3:39 PM |
Long time pattern (T) | DateTime.Now.ToString("T") | 3:39:46 PM |
Universal sortable date/time pattern (u) | DateTime.Now.ToString("u") | 2010-11-08 15:39:46Z |
Universal full date/time pattern (U) | DateTime.Now.ToString("U") | Monday, November 08, 2010 11:39:46 PM |
Year/month pattern (Y) | DateTime.Now.ToString("Y") | November, 2010 |
Format Description | Code Snippet | Output |
---|---|---|
Abbreviated month name, day and year | DateTime.Now.ToString("MMM d, yyyy") | Nov 8, 2010 |
Day of the week name plus month name and day of month | DateTime.Now.ToString("dddd, MMMM d") | Monday, November 8 |
Month/Day/Year, using exactly two digits for each | DateTime.Now.ToString("MM/dd/yy") | 11/08/10 |
Format Description | Code Snippet | Output |
---|---|---|
Relative time for date more than a year ago | var birthDate = new DateTime(2008, 9, 1 9, 45, 0); birthDate.ToRelativeDateString() | on September 1, 2008 |
Relative time for date several months ago | DateTime.Now.AddMonths(-6).ToRelativeDateString() | on May 8 |
Relative time for date five days ago | DateTime.Now.AddDays(-5).ToRelativeDateString() | five days ago |
Relative time for yesterday | DateTime.Now.AddDays(-1).ToRelativeDateString() | yesterday |
Relative time for several hours ago | DateTime.Now.AddHours(-3.14159).ToRelativeDateString() | three hours ago |
Relative time for more than five minutes ago | DateTime.Now.AddMinutes(-6.25).ToRelativeDateString() | six minutes ago |
Relative time for less than five minutes ago | DateTime.Now.AddMinutes(-2.5).ToRelativeDateString() | a few minutes ago |
Relative time for within past minute | DateTime.Now.AddSeconds(-15).ToRelativeDateString() | less than a minute ago |
Universal format for date in current year | DateTime.Now.ToUniversalFormat() | Monday, Nov 8 at 3:39 PM |
Universal format for date in other year | var birthDate = new DateTime(2008, 9, 1 9, 45, 0); birthDate.ToUniversalFormat() | Monday, Sep 1, 2008 at 9:45 AM |
7:17 PM
|
Labels:
.NET C# programming
|
This entry was posted on 7:17 PM
and is filed under
.NET C# programming
.
You can follow any responses to this entry through
the RSS 2.0 feed.
You can leave a response,
or trackback from your own site.
Subscribe to:
Post Comments (Atom)
2 comments:
Монголоор он сар өдөрийг монголоор харуулдаг зүйл байна уу?. Өөрийгөө зовоохгүйгээр? Jan.21.2011 гэж харуулдаг шиг. Эсвэл helper function ч юм уу?
Post a Comment