C#里面比较时间大小三种方法
来源:互联网 发布:类似bilibili的软件 编辑:程序博客网 时间:2024/04/29 08:55
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();
本文来自于CSDN博客
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();
本文来自于CSDN博客
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- C#里面比较时间大小三种方法
- 微软的某些东西,确实不敢恭维,其实,它可以做得更好
- voip穿越防火墙技术
- C# 操作 EXCEL
- 如何让 WebBrowser控件 使用BeforeNavigate2(...)屏蔽特定页面
- Swing 中进度指示器的使用(三)
- C#里面比较时间大小三种方法
- abstract class和interface的区别
- XBRL 在中国的未来趋势
- 无组件ASP验证码-GIF格式
- 改变背景图像或颜色
- ABAP- Get email address in HR from employee id.
- 15款远程控制软件
- 增强 并不是 所有情况都会 调用
- Perl 简介