本文整理汇总了C#中System.TimeSpan.FromTicks方法的典型用法代码示例。如果您正苦于以下问题:C# TimeSpan.FromTicks方法的具体用法?C# TimeSpan.FromTicks怎么用?C# TimeSpan.FromTicks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.TimeSpan
的用法示例。
在下文中一共展示了TimeSpan.FromTicks方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenTimeSpanFromTicks
// Example of the TimeSpan.FromTicks( long ) method.
using System;
class FromTicksDemo
{
static void GenTimeSpanFromTicks( long ticks )
{
// Create a TimeSpan object and TimeSpan string from
// a number of ticks.
TimeSpan interval = TimeSpan.FromTicks( ticks );
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}", ticks, timeInterval );
}
static void Main( )
{
Console.WriteLine(
"This example of TimeSpan.FromTicks( long )\n" +
"generates the following output.\n" );
Console.WriteLine( "{0,21}{1,18}",
"FromTicks", "TimeSpan" );
Console.WriteLine( "{0,21}{1,18}",
"---------", "--------" );
GenTimeSpanFromTicks( 1 );
GenTimeSpanFromTicks( 12345 );
GenTimeSpanFromTicks( 123456789 );
GenTimeSpanFromTicks( 1234567898765 );
GenTimeSpanFromTicks( 12345678987654321 );
GenTimeSpanFromTicks( 10000000 );
GenTimeSpanFromTicks( 600000000 );
GenTimeSpanFromTicks( 36000000000 );
GenTimeSpanFromTicks( 864000000000 );
GenTimeSpanFromTicks( 18012202000000 );
}
}
输出:
FromTicks TimeSpan --------- -------- 1 00:00:00.0000001 12345 00:00:00.0012345 123456789 00:00:12.3456789 1234567898765 1.10:17:36.7898765 12345678987654321 14288.23:31:38.7654321 10000000 00:00:01 600000000 00:01:00 36000000000 01:00:00 864000000000 1.00:00:00 18012202000000 20.20:20:20.2000000