如何求2个DATETIME之间相差几小时?(考虑跨年)
在线等 谢谢
在线等 谢谢
解决方案 »
- 跨线程调用COM接口的问题
- 在线等!!!关于combobox和txt文档结合的问题!!
- [调查]你所在的企业使用什么软件来处理内部信息的交流(UP可能有分)
- FTP断点续传,断开再次传替(续传)得到的文件不正确,答付给所有分!
- str.AppendFormat(formatString,str1,str2..)现在想给出一个变量i,根据i的不同后面的strn也不同,该怎么做?
- SOS:利用WPF RichTextBox 提取RTF, 莫名丢掉了Underline样式信息
- 【求助】删除数据库中记录的问题
- 关于BerkeleyDB在C#中的异常问题
- 能否实现定时读取数据库某个表中新添加的数据?
- 请问各位朋友那里有反编译DLL的工具呀!
- 关于一个想学习C#的新手的提问????????????????????????
- 100分请教, c# WinForm 如何运行时候,改变DataGrid 的字体背景色(依据数据值的不同)
int t1=DATETIME1.Hour;
int t2=DATETIME2.Hour;
然后相减
TotalHours就是TimeSpan的。
double cnt = span.TotalHours;
{
const string headerFmt = "\n{0,-45}";
const string dataFmt = "{0,-12}{1,8} {2,-18}{3,21}" ; // Display the properties of the TimeSpan parameter.
static void ShowTimeSpanProperties( TimeSpan interval )
{
Console.WriteLine( "{0,21}", interval );
Console.WriteLine( dataFmt, "Days", interval.Days,
"TotalDays", interval.TotalDays );
Console.WriteLine( dataFmt, "Hours", interval.Hours,
"TotalHours", interval.TotalHours );
Console.WriteLine( dataFmt, "Minutes", interval.Minutes,
"TotalMinutes", interval.TotalMinutes );
Console.WriteLine( dataFmt, "Seconds", interval.Seconds,
"TotalSeconds", interval.TotalSeconds );
Console.WriteLine( dataFmt, "Milliseconds",
interval.Milliseconds, "TotalMilliseconds",
interval.TotalMilliseconds );
Console.WriteLine( dataFmt, null, null,
"Ticks", interval.Ticks );
} static void Main( )
{
Console.WriteLine(
"This example of the TimeSpan class properties " +
"generates the \nfollowing output. It " +
"creates several TimeSpan objects and \ndisplays " +
"the values of the TimeSpan properties for each." ); // Create and display a TimeSpan value of 1 tick.
Console.Write( headerFmt, "TimeSpan( 1 )" );
ShowTimeSpanProperties( new TimeSpan( 1 ) ); // Create a TimeSpan value with a large number of ticks.
Console.Write( headerFmt, "TimeSpan( 111222333444555 )" );
ShowTimeSpanProperties( new TimeSpan( 111222333444555 ) ); // This TimeSpan has all fields specified.
Console.Write( headerFmt, "TimeSpan( 10, 20, 30, 40, 50 )" );
ShowTimeSpanProperties( new TimeSpan( 10, 20, 30, 40, 50 ) ); // This TimeSpan has all fields overflowing.
Console.Write( headerFmt,
"TimeSpan( 1111, 2222, 3333, 4444, 5555 )" );
ShowTimeSpanProperties(
new TimeSpan( 1111, 2222, 3333, 4444, 5555 ) ); // This TimeSpan is based on a number of days.
Console.Write( headerFmt, "FromDays( 20.84745602 )" );
ShowTimeSpanProperties( TimeSpan.FromDays( 20.84745602 ) );
}
}