格式: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) > 0) Console.WriteLine(st1+">"+st2);
else if (DateTime.Compare(t1, t2) == 0) Console.WriteLine(st1+"="+st2);
else Console.WriteLine(st1+"<"+st2);if (DateTime.Compare(t1, t3) > 0) Console.WriteLine("\r\n"+st1 + ">" + t3.ToString());
else if (DateTime.Compare(t1, t3) == 0) Console.WriteLine("\r\n" + st1 + "=" + t3.ToString());
else Console.WriteLine("\r\n" + st1 + "<" + t3.ToString());

时间比较方法DateTime.Compare相关推荐

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

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

  2. C# DateTime.Compare判断两个DateTime 日期是否相等

    DateTime t1 = DateTime.Now.Date; //2020/8/4 0:00:00 DateTime t2 = Convert.ToDateTime(DateTime.Now.To ...

  3. python时间处理模块datetime+dateutil、numpy时间处理模块datetime64以及pandas时间处理模块Timestamp的演化路径及常用处理接口

    python时间处理模块datetime+dateutil.numpy时间处理模块datetime64以及pandas时间处理模块Timestamp及常用处理接口 python时间处理模块dateti ...

  4. python常用时间处理方法

    常用时间处理方法 今天 today = datetime.date.today() 昨天 yesterday = today - datetime.timedelta(days=1) 上个月 last ...

  5. 【万字长文】详解Python时间处理模块-datetime

    datetime模块提供了用于处理日期和时间的类和对应的方法,一般用于处理年.月.日.时.分.秒的统计和计算等需求.在支持日期时间数学运算的同时,实现的关注点更着重于如何能够更有效地解析其属性用于格式 ...

  6. 【Python】8000字:Python时间系列之datetime模块

    公众号:尤而小屋 作者:Peter 编辑:Peter 大家好,我是Peter~ 在上篇Python或Pandas时间序列的文章中Peter详细介绍了time模块,本文中重点介绍的是datetime模块 ...

  7. python中dataframe合并列名日期到季度_python 处理dataframe中的时间字段方法

    在机器学习过程中,通常会通过pandas读取csv文件,保持成dadaframe格式,然而有时候需要对dataframe中的时间字段进行数据建模,比如时间格式为datetime,那么像一般操作data ...

  8. python时间计算_python datetime库使用和时间加减计算

    datetime库使用 一.操作当前时间 1.获取当前时间 >>> importdatetime>>> printdatetime.datetime.now()20 ...

  9. 【Python 标准库学习】日期和时间处理库 — datetime

    欢迎加入 Python 官方文档翻译团队:https://www.transifex.com/python-doc/ datetime 模块提供了可以通过多种方式操作日期和时间的类.在支持日期时间数学 ...

最新文章

  1. P2P征信 大数据堪当重任?
  2. 总结一下遇到的各种核函数
  3. win定时关机_两种方法让你设置电脑定时关机
  4. 使用 jQuery Mobile 与 HTML5 开发 Web App (十) —— jQuery Mobile 默认配置与事件基础
  5. 斐波那契数列的性质整理
  6. 使用AVPlayer制作一个播放器
  7. 给Ubuntu安装MacOS主题
  8. 由超高压的超导体猜测超导的真相
  9. 91卫图免费版使用步骤
  10. Graph_Master(连通分量_C_Trajan缩点+最小路径覆盖)
  11. 如何用 ISO 镜像制作 U 盘安装盘(通用方法、无需 WinPE)
  12. linux防恶意软件防病毒 防护工具
  13. R语言survival包coxph函数构建cox回归模型、ggrisk包ggrisk函数可视化Cox回归的风险评分图、使用cutoff包基于最小p值法方法计算最佳截断值(基于LIRI基因数据集)
  14. css本文在背景之上,css实现文字在背景图片之上
  15. 高级数据库三:浅谈数据库事务(transaction)
  16. 【数据结构】动态规划——找零钱问题解析(含c++和python代码)
  17. 计算年龄的sql语句
  18. PHP多人聊天系统,ttltCha​tPHP多人在线聊天系统软件源码 v0.0.12
  19. couldnt find pybind11Config.cmake
  20. Move Semantics and Perfect Forwarding in C++11

热门文章

  1. 微信支付:app端提示微信签名失败,errCode=-2;后台服务端返回成功
  2. 华三交换机irf 堆叠配置_H3C交换机堆叠的基本配置
  3. 在css的框中打文字,css 边框上如何写入文字?
  4. html文字如何显示在右侧,html点击左边代码右边显示相应的内容
  5. springboot 前缀_Springboot Redis设置key 前缀
  6. 蓝桥杯 ADV-154 算法提高 质数的后代
  7. 狠心刷完这 6 份 pdf,从15k涨薪到36k
  8. jupyter notebook 添加核 (jupyter:ModuleNotFoundError: No module named ‘torch‘) 亲测可用
  9. 【米思米机械设备知识分享】- 游标卡尺使用方法介绍
  10. 无法读取excel: Excel file format cannot be determined, you must specify an engine manually.建模题目的数据