格式:DateTime.Compare(datetime1, datetime2)

参数为时间格式,为第一个参数比较第二个参数,返回小于0的值,等于0或大于0的值。

实例:

 string st1 = "12:13";
string st2 = "14:13";
DateTime t1 = Convert.ToDateTime(st1);
Console.WriteLine(t1); //20186/6 下午 12:12:00
DateTime t2 = Convert.ToDateTime(st2);
Console.WriteLine(t2); //20186/6 下午 02:14:00
DateTime t3 = DateTime.Now;
Console.WriteLine(t3);
if (DateTime.Compare(t1, t2) > ) Console.WriteLine(st1+">"+st2);
else if (DateTime.Compare(t1, t2) == ) Console.WriteLine(st1+"="+st2);
else Console.WriteLine(st1+"<"+st2); if (DateTime.Compare(t1, t3) > ) Console.WriteLine("\r\n"+st1 + ">" + t3.ToString());
else if (DateTime.Compare(t1, t3) == ) Console.WriteLine("\r\n" + st1 + "=" + t3.ToString());
else Console.WriteLine("\r\n" + st1 + "<" + t3.ToString());

时间比较方法DateTime.Compare的更多相关文章

  1. C# 时间比较方法DateTime.Compare

    public static int Compare(DateTime t1,DateTime t2) 返回值 类型:System..::.Int32 有符号数字,指示 t1 和 t2 的相对值. 值类 ...

  2. C#学习基础资料记录---字典(Dictionary),时间表示方法(DateTime.Now),文件操作

    1.字典 https://www.cnblogs.com/gengaixue/p/4002244.html 2.时间的表示方法 DateTime.Now的多种用法 https://www.cnblog ...

  3. 使用DateTime的ParseExact方法实现特殊日期时间的方法详解(转)

    本篇文章是对使用DateTime的ParseExact方法实现特殊日期时间的方法进行了详细的分析介绍,需要的朋友参考下 今天遇到一个特别的需求,需要从下面的字符串中转换成一个DateTime对象: [ ...

  4. Python time datetime常用时间处理方法

    常用时间转换及处理函数: import datetime # 获取当前时间 d1 = datetime.datetime.now() print d1 # 当前时间加上半小时 d2 = d1 + da ...

  5. python操作日期和时间的方法

    不管何时何地,只要我们编程时遇到了跟时间有关的问题,都要想到 datetime 和 time 标准库模块,今天我们就用它内部的方法,详解python操作日期和时间的方法.1.将字符串的时间转换为时间戳 ...

  6. python时间处理之datetime

    python时间处理之datetime 标签: pythondateimportstringc 2012-09-12 23:21 20910人阅读 评论(0) 收藏 举报  分类: Python系列( ...

  7. 一个好的Java时间工具类DateTime

    此类的灵感来源于C# 虽然网上有什么date4j,但是jar太纠结了,先给出源码,可以继承到自己的util包中,作为一个资深程序员,我相信都有不少好的util工具类,我也希望经过此次分享,能带动技术大 ...

  8. Java8新特性时间日期库DateTime API及示例

    Java8新特性的功能已经更新了不少篇幅了,今天重点讲解时间日期库中DateTime相关处理.同样的,如果你现在依旧在项目中使用传统Date.Calendar和SimpleDateFormat等API ...

  9. Python 中的时间处理包datetime和arrow

    Python 中的时间处理包datetime和arrow 在获取贝壳分的时候用到了时间处理函数,想要获取上个月时间包括年.月.日等 # 方法一: today = datetime.date.today ...

随机推荐

  1. pdf预览

    从服务器取回pdf流数据,通过iframe在html页面展示 不废话,,直接代码: <html> <head> <meta charset="UTF-8&quo ...

  2. CentOS 7运维管理笔记(12)----PHP页面失去焦点后变成空白的解决方法

    昨天搭建好了LAMP服务器,可以正常看到PHP页面了.后来发现每当把鼠标从浏览器中移开而点击其他地方时,PHP页面就变成一片空白.即PHP页面失去焦点后就变空白,不知为何. 今天网上搜索解决方案,终于 ...

  3. CentOS 7运维管理笔记(4)----安装ftp服务器

    在CentOS 7下安装ftp服务器,可以使局域网内的主机拥有共享文件的一个站点. 在Linux系统下,vsftp是一款应用比较广泛的FTP软件,其特点是小巧轻快,安全易用.目前在开源操作系统中常用的 ...

  4. libcurl 使用

    关于libcurl的文章网络上很多, 这里不再描述. 以下是如何使用libcurl的例子.   一.常用函数     1) libcurl的全局初始化及释放 CURLcode curl_global_ ...

  5. gradle中文学习资料

    http://wiki.jikexueyuan.com/project/GradleUserGuide-Wiki/ https://www.gitbook.com/book/lippiouyang/g ...

  6. Fastdfs 部署干货

    tracker server and client:192.168.1.42 storage server:192.168.1.46 storage server:192.168.1.53 安装: 安 ...

  7. leetcode-surrounded regions-ZZ

    Problem Statement (link): Given a 2D board containing 'X' and 'O', capture all regions surrounded by ...

  8. Http协议和web本职【转自丁码农】

    当你在浏览器地址栏敲入“http://www.cnblogs.com/”,然后猛按回车,呈现在你面前的,将是博客园的首页了(这真是废话,你会认为这是理所当然的).作为一个开发者,尤其是web开发人员, ...

  9. python 类属性及限制

    Student类本身需要绑定一个属性直接在class中定义属性,这种属性是类属性,归Student类所有:class Student(object): name = 'Student'类的所有实例都可 ...

  10. liunx screen使用简单实验

    liunx screen使用 今天因工作需要使用到screen工具,感觉挺有意思,记录一下 GNU Screen是一款由GNU计划开发的用于命令行终端切换的自由软件.用户可以通过该软件同时连接多个本地 ...