C#里面比较时间大小三种方法
来源:互联网 发布:centos软件管理器 编辑:程序博客网 时间:2024/06/10 04:05
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#里面比较时间大小三种方法
- 在使用SSIS设计脚本时候,出现的在PostExecute之外不能锁定变量集合进行读写访问的问题的解决
- 判断页面文本框中输入的类型(数字,符号,字母,汉字)!!(2)
- C++中的虚函数
- uC/OS-II源码分析(二)
- uC/OS-II源码分析(三)
- C#里面比较时间大小三种方法
- string 内存泄漏 solaris 10
- 实现简单浮动层的基本方法
- jpeglib使用指南
- 动作与指令的区别
- test
- ASP.NET刷新页面的六种方法
- 职场不得不明白的十大定律
- asp.net千奇百怪的日历