DateTime&TimeSpan
DateTime类
表示时间上的一刻,通常以日期和当天的时间表示。
构造方法:
public DateTime(int,int,int)
创建指定年月日的时间对象,重载有多个方法,可以创建具有年月日时分秒的时间对象
public static int DaysInMonth(int year, int month)
返回指定年份月份的天数
public static int Compare(System.DateTime t1, System.DateTime t2)
返回两个时间之间的关系: 小于零 t1 早于 t2。 零 t1 与 t2 相同。 大于零 t1 晚于 t2。与该方法类似的CompareTo(System.DateTime t2) 非静态方法,实例对象相当于t1。
public bool Equals(System.DateTime value)
返回实例与另一个实例是否相等
public static System.DateTime Parse(string s)
将等效字符串转化为时间
public static bool TryParse(string s, out System.DateTime result)
将s转化为时间,返回是否成功。成功,result为s表示的时间;不成功result为System.DateTime.MinValue
public System.DateTime AddDays(double value)
返回一个将指定天数返回到实例上的日期,类似方法还有AddHours,AddMonths等
public System.DateTime Add(System.TimeSpan value)
返回一个将指定时间间隔返回到实例上的日期
TimeSpan 类
表示一个时间间隔
public TimeSpan(int hours, int minutes, int seconds)
实例化一个时间间隔
public static System.TimeSpan Parse(string s)
public static bool TryParse(string s, out System.TimeSpan result)
类似于DateTime的这些方法
public static System.TimeSpan FromDays(double value)
返回一个指定天数的实例类似方法有FromHours,FromSeconds等