zoukankan      html  css  js  c++  java
  • 求两个时间相差多少时间

    Add:与另一个TimeSpan值相加。
    Days:返回用天数计算的TimeSpan值。
    Duration:获取TimeSpan的绝对值。
    Hours:返回用小时计算的TimeSpan值
    Milliseconds:返回用毫秒计算的TimeSpan值。
    Minutes:返回用分钟计算的TimeSpan值。
    Negate:返回当前实例的相反数。
    Seconds:返回用秒计算的TimeSpan值。
    Subtract:从中减去另一个TimeSpan值。
    Ticks:返回TimeSpan值的tick数。
    TotalDays:返回TimeSpan值表示的天数。
    TotalHours:返回TimeSpan值表示的小时数。
    TotalMilliseconds:返回TimeSpan值表示的毫秒数。
    TotalMinutes:返回TimeSpan值表示的分钟数。
    TotalSeconds:返回TimeSpan值表示的秒数。

    原文

    DateTime DateTime1, DateTime2;

    DateTime2 = DateTime.Now; //现在时间
    DateTime1 = Convert.ToDateTime("2009-04-24 20:00:00"); //设置要求的减的时间
    string dateDiff = null;
    TimeSpan ts1 = new TimeSpan(DateTime1.Ticks);
    TimeSpan ts2 = new TimeSpan(DateTime2.Ticks);
    TimeSpan ts = ts1.Subtract(ts2).Duration(); //计算ts1,ts2的时间差==时间差是秒,Ticks是秒;两个时间一共差了多少秒,然后秒转换成天,小时,分钟。。。
    dateDiff = ts.Days.ToString() + "天" + ts.Hours.ToString() + "小时" + ts.Minutes.ToString() + "分钟" + ts.Seconds.ToString() + "秒";

  • 相关阅读:
    正则表达式在NLP中应用
    spring boot中 异常:Error resolving template "xxx", template might not exist or might not be accessible...解决办法
    毕业设计6
    毕业设计5
    毕业设计4
    毕业设计3
    毕业设计2
    毕业设计1
    支付宝架构
    Javaee应用架构
  • 原文地址:https://www.cnblogs.com/ZkbFighting/p/9553307.html
Copyright © 2011-2022 走看看