本文整理汇总了C#中System.TimeSpan.FromHours方法的典型用法代码示例。如果您正苦于以下问题:C# TimeSpan.FromHours方法的具体用法?C# TimeSpan.FromHours怎么用?C# TimeSpan.FromHours使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.TimeSpan
的用法示例。
在下文中一共展示了TimeSpan.FromHours方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenTimeSpanFromHours
// Example of the TimeSpan.FromHours( double ) method.
using System;
class FromHoursDemo
{
static void GenTimeSpanFromHours( double hours )
{
// Create a TimeSpan object and TimeSpan string from
// a number of hours.
TimeSpan interval = TimeSpan.FromHours( hours );
string timeInterval = interval.ToString( );
// Pad the end of the TimeSpan string with spaces if it
// does not contain milliseconds.
int pIndex = timeInterval.IndexOf( ':' );
pIndex = timeInterval.IndexOf( '.', pIndex );
if( pIndex < 0 ) timeInterval += " ";
Console.WriteLine( "{0,21}{1,26}", hours, timeInterval );
}
static void Main( )
{
Console.WriteLine(
"This example of TimeSpan.FromHours( double )\n" +
"generates the following output.\n" );
Console.WriteLine( "{0,21}{1,18}",
"FromHours", "TimeSpan" );
Console.WriteLine( "{0,21}{1,18}",
"---------", "--------" );
GenTimeSpanFromHours( 0.0000002 );
GenTimeSpanFromHours( 0.0000003 );
GenTimeSpanFromHours( 0.0012345 );
GenTimeSpanFromHours( 12.3456789 );
GenTimeSpanFromHours( 123456.7898765 );
GenTimeSpanFromHours( 0.0002777 );
GenTimeSpanFromHours( 0.0166666 );
GenTimeSpanFromHours( 1 );
GenTimeSpanFromHours( 24 );
GenTimeSpanFromHours( 500.3389445 );
}
}
输出:
FromHours TimeSpan --------- -------- 2E-07 00:00:00.0010000 3E-07 00:00:00.0010000 0.0012345 00:00:04.4440000 12.3456789 12:20:44.4440000 123456.7898765 5144.00:47:23.5550000 0.0002777 00:00:01 0.0166666 00:01:00 1 01:00:00 24 1.00:00:00 500.3389445 20.20:20:20.2000000