.net用新的日期方法,就是使用Int64来代替Double类型储存时间。但仍然提供了转换为老类型日期的方法,就是DataTime的ToOADate和FormOADate方法。你在MSDN中输入这些关键字,就能很快找到使用方法。
DateTime baseDate = new DateTime(1899, 12, 30);
double baseNumber = baseDate.ToOADate();// convert the datetime to double
double doubleValue = 0;
DateTime doubleDate = DateTime.FromOADate(doubleValue);// convert the double to datetime
Console.WriteLine(baseNumber);//0
Console.WriteLine(doubleDate.ToString());//12/30/1899 12:00:00 AM
Console.WriteLine(doubleDate.ToString("yyyy-MM-dd HH:mm:ss"));//1899-12-30 00:00:00
double baseNumber = baseDate.ToOADate();// convert the datetime to double
double doubleValue = 0;
DateTime doubleDate = DateTime.FromOADate(doubleValue);// convert the double to datetime
Console.WriteLine(baseNumber);//0
Console.WriteLine(doubleDate.ToString());//12/30/1899 12:00:00 AM
Console.WriteLine(doubleDate.ToString("yyyy-MM-dd HH:mm:ss"));//1899-12-30 00:00:00