我有一个gridview绑定到db的数据表.其中一列是日期时间字段,我必须在短期模式下读取(mm/dd/yyyy).但是,我想知道是否有任何容易从单元格或显示时间的日期时间删除年份.
//Convert the "date" column to only appear in mm/dd format
foreach (GridViewRow row in GridView1.Rows)
{
String myS = row.Cells[2].Text;
DateTime dt = DateTime.Parse(row.Cells[2].Text);
row.Cells[2].Text = dt.ToShortDateString();
}
Run Code Online (Sandbox Code Playgroud)
Dav*_*ish 11
使用标准ToString日期格式化程序,大写MM意思是"月月"和小写dd"白天"
row.Cells[2].Text = dt.ToString("MM/dd");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2357 次 |
| 最近记录: |