C#中时间大小的比较方法
来源:互联网 发布:淘宝普通会员 编辑:程序博客网 时间:2024/04/28 10:30
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#比较时间大小三种方法
- Struts2中在页面中比较时间大小的方法
- Mysql中时间加减和比较大小的方法
- Mysql中时间加减和比较大小的方法
- c#比较时间大小
- NET实用教程之C#三种比较时间大小、比较日期的方法
- Javascript中比较两个时间的大小
- js中比较时间的大小
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- LoadLibrary("TestOCX.ocx") failed-The specified module could not be found
- Spring
- FlashBuilder环境下使用Starling出现的问题收集整理
- 数据库优化方案
- 嵌入式Linux的特点
- C#中时间大小的比较方法
- c++ STL中元素替换功能的强大函数
- Oracle R安装文档的错误
- iPhone开发之UIScrollView初步
- 仅通过崩溃地址找出源代码的出错行
- 排序数组中和为给定值的两个数字
- Oracle数据库常用语句,慢慢收集中...
- 安卓TXT阅读器分享
- LVS+keepalived负载均衡