两个时间相减

<1>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime t1 = DateTime.Parse("2007-01-01");
            DateTime t2 = DateTime.Parse("2006-01-01");

            System.TimeSpan t3 = t1 - t2;  //两个时间相减 。默认得到的是 两个时间之间的天数   得到:365.00:00:00

            double getDay = t3.TotalDays; //将这个天数转换成天数, 返回值是double类型的(其实不必转换,因为t3默认就是天数) 得到:

            double getHours = t3.TotalHours; //将这个天数转换成小时, 返回值是double类型的

            double getMinute = t3.TotalMinutes; //将这个天数转换成分钟, 返回值是double类型的

            double getSeconds = t3.TotalSeconds; //将这个天数转换成秒数, 返回值是double类型的

            double getMillisecond = t3.TotalMilliseconds; ////将这个天数转换成毫秒, 返回值是double类型的

            Console.WriteLine(t3);  //输出:365.00:00:00
            Console.WriteLine(getDay); //输出:365
            Console.WriteLine(getHours); //输出:8760
            Console.WriteLine(getMinute); //输出:525600
            Console.WriteLine(getSeconds); //输出:31536000
            Console.WriteLine(getMillisecond); //输出:31536000000
            Console.ReadKey();
        }
  
时间: 2024-08-10 16:50:52

两个时间相减的相关文章

oracle 两个时间相减

oracle 两个时间相减默认的是天数 oracle 两个时间相减默认的是天数*24 为相差的小时数 oracle 两个时间相减默认的是天数*24*60 为相差的分钟数 oracle 两个时间相减默认的是天数*24*60*60 为相差的秒数 --MONTHS_BETWEEN(date2,date1) 给出date2-date1的月份 SQL> select months_between('19-12月-1999','19-3月-1999') mon_between from dual; MON_

C#两个时间相减

原文地址:http://www.jb51.net/article/60177.htm using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test { class Program { static void Main(string[] args) { DateTime t1 = DateTime.Parse("2007-01-01"); DateT

MySQL两个时间相减

SELECT TIMESTAMPDIFF(MONTH,'2009-10-01','2009-09-01'); interval可是: SECOND 秒 SECONDS MINUTE 分钟 MINUTES HOUR 时间 HOURS DAY 天 DAYS MONTH 月 MONTHS YEAR 年 YEARS 原文地址:https://www.cnblogs.com/bulrush/p/10397168.html

Java计算年月日时分秒时间差(两个时间相减)

//测试主方法  public static void main(String[] args) {          Date currentTime = df.parse("2004-03-26 13:31:40");   //当前系统时间             Date firstTime = df.parse("2004-01-02 11:30:24");     //查询的数据时间          String str=getTime(currentTi

怎样用php实现两个时间相减,得到相差的天数

//第一种方法 $time1 = mktime(10,20,30,2,5,2000); //2000-2-5 10:20:30$time2 = mktime(18,30,20,5,2,2000); //2000-5-2 18:30:20 //第二种方法 $time1= '2010-7-1';$time2='2010-7-8';//计算两者差值$days=abs((strtotime($date1)-strtotime($date2))/86400);$diff = (int)(($time2-$

Oracle 时间相减得出毫秒、秒、分、时、天,,【转】

http://blog.csdn.net/redarmy_chen/article/details/7351410 oracle 两个时间相减默认的是天数 oracle 两个时间相减默认的是天数*24 为相差的小时数 oracle 两个时间相减默认的是天数*24*60 为相差的分钟数 oracle 两个时间相减默认的是天数*24*60*60 为相差的秒数 --MONTHS_BETWEEN(date2,date1) 给出date2-date1的月份 SQL> select months_betwe

JAVA基础学习之final关键字、遍历集合、日期类对象的使用、Math类对象的使用、Runtime类对象的使用、时间对象Date(两个日期相减)

1.final关键字和.net中的const关键字一样,是常量的修饰符,但是final还可以修饰类.方法.写法规范:常量所有字母都大写,多个单词中间用 "_"连接. 2.遍历集合ArrayList<Integer> list = new ArrayList<Integer>();list.add(1);list.add(3);list.add(5);list.add(7);// 遍历List方法1,使用普通for循环:for (int i = 0; i <

asp.net(C#)时间相减 得到天数、小时、分钟、秒差

asp.net(C#)时间相减 得到天数.小时.分钟.秒差 DateTime dtone = Convert.ToDateTime("2007-1-1 05:00:00"); DateTime dtwo = Convert.ToDateTime("2007-1-5 08:00:00"); TimeSpan span = dtone.Subtract(dtwo); //算法是dtone 减去 dtwo tss.Text = span.Days + "天&qu

不同数据库中两列字段相减(某列有空值)

数据库中两个字段相减(某列有空值)处理方法: sql server中:select (isnull(字段1,0)-isnull(字段2,0)) as 结果 from 表 oracle中:select (nvl(字段1,0)-nvl(字段2,0)) as 结果 from 表 mysql中:select (ifnull(字段1,0)=ifnull(字段2,0)) as 结果 from 表 不同数据库中两列字段相减(某列有空值),码迷,mamicode.com