Saturday, May 19, 2012

Date Time string formatting in ASP.NET

December 24, 2009 by · 1 Comment 

With the following code you can format a DateTime within a Databind.

<%# DateTime.Parse(Eval("DateModified").ToString()).ToString("MM-dd-yyyy")%>

Some more format specifiers that can change format of datetime objects the way it is required.

Format specifier Name
d Short date pattern
D Long date pattern
t Short time pattern
T Long time pattern
f Full date/time pattern ( short time )
F Full date/time pattern ( long time )
g General date/time pattern ( short time )
G General date/time pattern ( long time )
M or m Month day pattern
R or r RFC1123 pattern
s Sortable date/time pattern; conforms to ISO 8601
u Universal sortable date/time pattern
U Universal sortable date/time pattern
Y or y Year month pattern
Top Blogs

Comments

One Response to “Date Time string formatting in ASP.NET”
  1. ZAREMA says:

    Thanks the author for article. The main thing do not forget about users, and continue in the same spirit.

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

*