本帖最后由 The_Enternal 于 2014-7-10 23:25 编辑  
 
具体代码如下- using System;
 
 - using System.Collections.Generic;
 
 - using System.Text;
 
 - using System.Diagnostics;
 
  
- namespace TimeSpan
 
 - {
 
  
-     public class TimeSpan
 
 -     {
 
 -         static void Main(string[] args)
 
 -         {
 
 -             //定义两个日期分别为2014年7月10号和2014年8月15号
 
 -             DateTime dateNow = new DateTime(2014, 7, 10);
 
  
-             DateTime dateFuther = new DateTime(2014, 8, 15);
 
 -             //TimeSpan类变量用来存储两个日期的间隔
 
 -             TimeSpan days = dateFuther - dateNow;
 
 -             //将两个日期都转换成段日期格式,days.TotalDays为总天数
 
 -             Console.WriteLine("{0}与{1}相差{2}天",dateNow.ToShortDateString(),dateFuther.ToShortDateString(),days.TotalDays);
 
  
-                 Console.ReadKey();
 
 -         }
 
 -     }
 
 - }
 
 
  复制代码 这是运行结果 
 
 
 
 
 |