C#里面比较时间大小三种方法
来源:互联网 发布:淘宝怎么搜索不了店铺 编辑:程序博客网 时间:2024/06/10 08:40
1。比较时间大小的实验
string st1="12:13";
string st2="14:14";
DateTime dt1=Convert.ToDateTime(st1);
DateTime dt2=Convert.ToDateTime(st2);
DateTime dt3=DateTime.Now;
if(DateTime.Compare(dt1,dt2)>0)
msg.Text=st1+">"+st2;
else
msg.Text=st1+"<"+st2;
msg.Text+="/r/n"+dt1.ToString();
if(DateTime.Compare(dt1,dt3)>0)
msg.Text+="/r/n"+st1+">"+dt3.ToString();
else
msg.Text+="/r/n"+st1+"<"+dt3.ToString();
2。计算两个时间差值的函数,返回时间差的绝对值:
private string DateDiff(DateTime DateTime1,DateTime DateTime2)
{
string dateDiff=null;
try
{
TimeSpan ts1=new TimeSpan(DateTime1.Ticks);
TimeSpan ts2=new TimeSpan(DateTime2.Ticks);
TimeSpan ts=ts1.Subtract(ts2).Duration();
dateDiff=ts.Days.ToString()+"天"
+ts.Hours.ToString()+"小时"
+ts.Minutes.ToString()+"分钟"
+ts.Seconds.ToString()+"秒";
}
catch
{
}
return dateDiff;
}
3。实现计算DateTime1-36天=DateTime2的功能
TimeSpan ts=new TimeSpan(40,0,0,0);
DateTime dt2=DateTime.Now.Subtract(ts);
msg.Text=DateTime.Now.ToString()+"-"+ts.Days.ToString()+"天/r/n";
msg.Text+=dt2.ToString();
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- ASP.NET网站中的安全问题
- 日志
- C#中close和dispose的区别
- 一个比较好用的SQL分页查询
- 在C#中ref和out的区别
- C#里面比较时间大小三种方法
- DataGridView新特色、常用操作
- 这也算是日志吧
- 毕业后5年决定命运
- 过两天发些老东西吧,传世不多了。
- 《三国演义》中死不瞑目的十大风流人物
- 中国人奉承人的通用方式?
- 动物生死观
- 西施失踪谜案:功成名就后被杀人灭口?