码迷,mamicode.com
首页 > Windows程序 > 详细

C# 日期时间

时间:2017-03-09 14:27:25      阅读:256      评论:0      收藏:0      [点我收藏+]

标签:add   rcu   日期时间   一周   ring   current   bsp   c#   格式化   

1、获取当前时间

string strCurrentDate=DateTime.Now.ToString();        //2017/03/09 12:48:45 

如果想要得到某种格式得日期时间,则可以如下进行格式化

string strCurrentDate=DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");  //2017-03-09 12:54:07

string strCurrentDate=DateTime.Now.ToString("yyyy-MM-dd");  //2017-03-09

string strCurrentDate=DateTime.Now.ToString("hh:mm:ss");  //12:54:07

2、获取当前时间往前推一周

string strCurrentDate=DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd hh:mm:ss");  //2017-03-02 12:54:07

3、获取当前时间往前推一个小时

string strCurrentDate = DateTime.Now.AddHours(-1).ToString("yyyy-MM-dd hh:mm:ss");  //2017-03-09 11:54:07

C# 日期时间

标签:add   rcu   日期时间   一周   ring   current   bsp   c#   格式化   

原文地址:http://www.cnblogs.com/awaTangjay/p/6525461.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!