TimeSpan.FromTicks(Int64) Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Devolve a TimeSpan que representa um tempo especificado, onde a especificação está em unidades de ticks.
public:
static TimeSpan FromTicks(long value);
public static TimeSpan FromTicks(long value);
static member FromTicks : int64 -> TimeSpan
Public Shared Function FromTicks (value As Long) As TimeSpan
Parâmetros
- value
- Int64
Um número de assinalações que representam um tempo.
Devoluções
Um objeto que representa value.
Exemplos
O exemplo seguinte cria vários TimeSpan objetos usando o FromTicks método.
// 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 );
}
}
/*
This example of TimeSpan.FromTicks( long )
generates the following output.
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
*/
// Example of the TimeSpan.FromTicks( long ) method.
open System
let genTimeSpanFromTicks ticks =
// Create a TimeSpan object and TimeSpan string from
// a number of ticks.
let interval = TimeSpan.FromTicks ticks
let timeInterval = string interval
// Pad the end of the TimeSpan string with spaces if it
// does not contain milliseconds.
let pIndex = timeInterval.IndexOf ':'
let pIndex = timeInterval.IndexOf('.', pIndex)
let timeInterval =
if pIndex < 0 then timeInterval + " "
else timeInterval
printfn $"{ticks,21}{timeInterval,26}"
printfn "This example of TimeSpan.FromTicks( long )\ngenerates the following output.\n"
printfn "%21s%18s" "FromTicks" "TimeSpan"
printfn "%21s%18s" "---------" "--------"
genTimeSpanFromTicks 1
genTimeSpanFromTicks 12345
genTimeSpanFromTicks 123456789
genTimeSpanFromTicks 1234567898765L
genTimeSpanFromTicks 12345678987654321L
genTimeSpanFromTicks 10000000
genTimeSpanFromTicks 600000000
genTimeSpanFromTicks 36000000000L
genTimeSpanFromTicks 864000000000L
genTimeSpanFromTicks 18012202000000L
(*
This example of TimeSpan.FromTicks( long )
generates the following output.
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
*)
' Example of the TimeSpan.FromTicks( Long ) method.
Module FromTicksDemo
Sub GenTimeSpanFromTicks( ticks As Long )
' Create a TimeSpan object and TimeSpan string from
' a number of ticks.
Dim interval As TimeSpan = TimeSpan.FromTicks( ticks )
Dim timeInterval As String = interval.ToString( )
' Pad the end of the TimeSpan string with spaces if it
' does not contain milliseconds.
Dim pIndex As Integer = timeInterval.IndexOf( ":"c )
pIndex = timeInterval.IndexOf( "."c, pIndex )
If pIndex < 0 Then timeInterval &= " "
Console.WriteLine( "{0,21}{1,26}", ticks, timeInterval )
End Sub
Sub Main( )
Console.WriteLine( _
"This example of TimeSpan.FromTicks( Long )" & _
vbCrLf & "generates the following output." & vbCrLf )
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 )
End Sub
End Module
' This example of TimeSpan.FromTicks( Long )
' generates the following output.
'
' 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
Observações
Este é um método de conveniência com o mesmo comportamento do TimeSpan.TimeSpan(Int64) construtor. Um único tick representa cem nanossegundos ou um décimo milionésimo de segundo. Há 10.000 tiques num milissegundo.