![29929f1033269c8d6f70b8025aa6d541.png](https://img-blog.csdnimg.cn/img_convert/29929f1033269c8d6f70b8025aa6d541.png)
主要使用ToLongDateString、ToShortDateString、ToLongTimeString、ToShortTimeString、DayOfWeek等获取日期、时间、星期等数据。
![74a47448519281a99354de9417088918.png](https://img-blog.csdnimg.cn/img_convert/74a47448519281a99354de9417088918.png)
MM =两位数月份
mm =两位数分钟
HH =两位小时,24小时制
hh =两位小时,12小时制
string br = "
"; string a1 = DateTime.Now.ToString(); string a2 = DateTime.Now.ToString("yyyy-MM-dd"); string a3 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); string a4 = DateTime.Now.ToString("yyyyMMddHHmmss"); string a5 = DateTime.Now.ToLongDateString().ToString(); string a6 = DateTime.Now.ToString("hh:mm:ss"); string a7 = DateTime.Now.Year.ToString(); string a8 = DateTime.Now.DayOfWeek.ToString(); Response.Write(a1 + br); Response.Write(a2 + br); Response.Write(a3 + br); Response.Write(a4 + br); Response.Write(a5 + br); Response.Write(a6 + br); Response.Write(a7 + br); Response.Write(a8 + br);
显示的效果如下图:
![6e1ec035b792530fcc033b560ecd7c67.png](https://img-blog.csdnimg.cn/img_convert/6e1ec035b792530fcc033b560ecd7c67.png)