zengdj

点滴经验,源自实践

博客园 首页 新随笔 联系 订阅 管理
格式化DataGrid的日期字段

用指定的输出格式来输出日期:
如下例所示:Indberetning的类型为日期(DateTime),要求输出短日期格式。
<ItemTemplate>
                    
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Indberettet","{0:d}") %>' ID="Label1"/>
                
</ItemTemplate>

又如自定义输出格式, 2005-08-24:
DataBinder.Eval(Container,"DataItem.Indberetning","{0:yy-MM-dd}")

标准的日期格式: (Standard datatime format strings)
d 短日期格式 参考DateTimeFormatInfo.ShortDatePattern属性
D 长日期格式 参考DateTimeFormatInfo.LongDatePattern 属性
t 短时间格式 参考DateTimeFormatInfo.ShortTimePattern属性
T 长时间格式 参考DateTimeFormatInfo.LongTimePattern 属性
f 全日期格式(short time) Displays a combination of the long date and short time patterns, separated by a space.
F 全日期格式(long time) 参考DateTimeFormatInfo.FullDateTimePattern 属性
g General date/time pattern (short time) Displays a combination of the short date and short time patterns, separated by a space.
G General date/time pattern (long time) Displays a combination of the short date and long time patterns, separated by a space.
M or m Month day pattern 参考DateTimeFormatInfo.MonthDayPattern 属性
R or r RFC1123 pattern 参考 DateTimeFormatInfo.RFC1123Pattern属性
s Sortable date/time pattern; conforms to ISO 8601 参考DateTimeFormatInfo.SortableDateTimePattern 属性
u Universal sortable date/time pattern 参考DateTimeFormatInfo.UniversalSortableDateTimePattern属性
U Universal sortable date/time pattern 参考DateTimeFormatInfo.FullDateTimePattern 属性
Y or y Year month pattern 参考DateTimeFormatInfo.YearMonthPattern 属性


其他自定义日期格式(Custom Datetime format strings):
d 显示一位日期(显示9,不显示09)
dd 显示二位日期(显示09)
ddd 显示日期的缩略名,参考DateTimeFormatInfo.AbbreviatedDayNames属性
ddd 显示全日期
f 显示毫秒(一位)
ff 显示二位毫秒
fff 显示三位毫秒
ffff 显示四位毫秒
fffff 显示五位毫秒
ffffff 显示六位毫秒
fffffff 显示七位毫秒
h 显示小时(显示一位,1-12)
hh 显示小时(显示两位,1-12)
H 显示小时(显示一位,00-23)
HH 显示小时(显示两位,00-23)
m 显示分钟(显示一位,0-59),如5显示为5
mm 显示分钟(显示两位,0-59),如5显示为05
M 显示月(显示一位,1-12)
MM 显示月(显示两位,1-12),如5显示为05
MMM 显示月份的简称,参考DateTimeFormatInfo.AbbreviatedMonthNames属性
MMMM 显示月份的全称,参考DateTimeFormatInfo.MonthNames属性
s 显示秒(显示一位,0-59),如5显示为5
ss 显示秒(显示两位,0-59),如5显示为05
t 显示A.M/P.M的第一个字符,参考DateTimeFormatInfo.AMDesignator/PMDesignator属性
tt 显示A.M/P.M的全部,参考DateTimeFormatInfo.AMDesignator/PMDesignator属性
y 显示两位年,如2005显示为5
yy 显示两位年,如2005显示为05
yyyy 显示四位年,如2005显示为2005
z/zz/zzz,zzz 显示时区信息(详见MSDN)
g/gg 显示A.D.(公元)
posted on 2005-07-25 18:00  DingJun  阅读(576)  评论(0)    收藏  举报