web analytics

Date Time string formatting in ASP.NET

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

One thought on “Date Time string formatting in ASP.NET

  • March 19, 2010 at 8:00 am

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

Leave a Reply

%d bloggers like this: