ToShortDateString() .
(2011-09-29 10:56:49)
就是把你所操作的时间改变成短时间类型例如:2008/1/20 如果直接用tostring()则现实的时间是默认的格式
例如:2008-1-20 11:44:47
举例:DateTime.Now.Date.ToShortDateString();
输出:2008/1/20
如果DateTime.Now.Date.ToString();
2008-1-20 11:44:47
ToShortDateString 方法所返回的字符串区分区域性。它反映当前区域性的 DateTimeFormatInfo
对象所定义的模式。例如,对于 en-US 区域性,标准短日期模式为“M/d/yyyy”;对于 de-DE
区域性,该模式为“dd.MM.yyyy”;对于 ja-JP
区域性,该模式为“yyyy/M/d”。此外,也可以在特定计算机上自定义特定格式字符串,以便该字符串不同于标准短日期格式字符串。
日期用ToShortDateString格式化,为什么换了机器以后得出来的不是xxxx-xx-x的形式,而是x/xx/xxxx?
只要在控制面板中的"区域和语言选项"设置"区域选项"就行了
string d1 = DateTime.Now.Date.ToShortDateString();//2004-8-12
string d2 =
DateTime.Now.ToShortTimeString();//16:42
string d3 = DateTime.Now.ToString("yyyy-MM-dd
hh:mm:ss");//2004-08-12 04:42:34
string d4 =
DateTime.Now.ToString("yyyy-MM-dd");//2004-08-12
string d5 =
DateTime.Now.ToString("HH:mm:ss");//16:42:41
DateTime dtcreate;
string strDate = string.Empty;
if (DateTime.TryParse(dt.Rows[i]["CreateDate"].ToString(), out
dtcreate))
{
strDate
= dtcreate.ToShortDateString();
}
|