DateTime的时间格式化(DateTimeFormatInfo使用)
2009-12-08 15:11
337 查看
直接可以使用
DateTime.ToString("yyyy-MM-dd");
或者使用DateTimeFormatInfo方式实现
DateTime dt;
DateTimeFormatInfo dtFormat = new System.Globalization.DateTimeFormatInfo();
dtFormat.ShortDatePattern="yy-MM-dd" ;
dt=Convert.ToDateTime("04-05-06",dtFormat);
Response.Write(dt.ToString("yyyy-MM-dd"));
dtFormat.ShortDatePattern="MM-dd-yy" ;
dt=Convert.ToDateTime("04-05-06",dtFormat);
Response.Write(dt.ToString("yyyy-MM-dd"));
dtFormat.ShortDatePattern="dd-MM-yy" ;
dt=Convert.ToDateTime("04-05-06",dtFormat);
Response.Write(dt.ToString("yyyy-MM-dd"));
DateTime.ToString("yyyy-MM-dd");
或者使用DateTimeFormatInfo方式实现
DateTime dt;
DateTimeFormatInfo dtFormat = new System.Globalization.DateTimeFormatInfo();
dtFormat.ShortDatePattern="yy-MM-dd" ;
dt=Convert.ToDateTime("04-05-06",dtFormat);
Response.Write(dt.ToString("yyyy-MM-dd"));
dtFormat.ShortDatePattern="MM-dd-yy" ;
dt=Convert.ToDateTime("04-05-06",dtFormat);
Response.Write(dt.ToString("yyyy-MM-dd"));
dtFormat.ShortDatePattern="dd-MM-yy" ;
dt=Convert.ToDateTime("04-05-06",dtFormat);
Response.Write(dt.ToString("yyyy-MM-dd"));
相关文章推荐
- 用DateTimeFormatInfo格式化日期时间(C#)
- 用DateTimeFormatInfo格式化日期时间
- DateTime.ToString格式化日期,使用DateDiff方法获取日期时间的间隔数
- DateTime.UtcNow.ToString(DateFormat) 时间格式化问题
- C# date format 使用C#格式化时间
- 使用DateFormat把时间长度格式化为"时:分:秒"格式
- ASP.NET GridView控件在列上格式化时间及DataFormatString使用
- 【转】使用DateFormat把时间长度格式化为"时:分:秒"格式--不错
- 【AspNetCore】【WebApi】扩展Webapi中的RouteConstraint中,让DateTime类型,支持时间格式化(DateTimeFormat)
- java 使用simpleDateFormat格式化日期 时间
- go time Format 格式化时间的使用
- Asp 时间格式化函数 FormatDateTime
- FormatDateTime格式化系统时间的问题
- xslt格式化日期和时间:使用ms:format-date、ms:format-time
- java 使用simpleDateFormat格式化日期 时间
- smarty中用date_format格式化时间的时候使用汉字的解决方法
- 在页面格式化获取时间的月份、年份、日(使用<fmt:formatDate> 标签)
- 使用DurationFormatUtils把时间区间格式化为"天 时:分:秒"
- String.Format,DateTime日期时间格式化集锦
- String.Format,DateTime日期时间格式化集锦,备忘录