TimeSpan-Konstruktor (Int64)
Initialisiert eine neue TimeSpan für die angegebene Anzahl Ticks.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Public Sub New ( _
ticks As Long _
)
'Usage
Dim ticks As Long
Dim instance As New TimeSpan(ticks)
public TimeSpan (
long ticks
)
public:
TimeSpan (
long long ticks
)
public TimeSpan (
long ticks
)
public function TimeSpan (
ticks : long
)
Parameter
- ticks
Eine in der Einheit 100 Nanosekunden ausgedrückte Zeitspanne.
Beispiel
Im folgenden Codebeispiel werden verschiedene TimeSpan-Objekte mithilfe der Konstruktorüberladung erstellt, die eine TimeSpan mit einer angegebenen Anzahl von Ticks initialisiert.
' Example of the TimeSpan( Long ) constructor.
Imports System
Imports Microsoft.VisualBasic
Module TimeSpanCtorLDemo
' Create a TimeSpan object and display its value.
Sub CreateTimeSpan( ticks As Long )
Dim elapsedTime As New TimeSpan( ticks )
' Format the constructor for display.
Dim ctor AS String = _
String.Format( "TimeSpan( {0} )", ticks )
' Pad the end of a TimeSpan string with spaces if
' it does not contain milliseconds.
Dim elapsedStr As String = elapsedTime.ToString( )
Dim pointIndex As Integer = elapsedStr.IndexOf( ":"c )
pointIndex = elapsedStr.IndexOf( "."c, pointIndex )
If pointIndex < 0 Then elapsedStr &= " "
' Display the constructor and its value.
Console.WriteLine( "{0,-33}{1,24}", ctor, elapsedStr )
End Sub
Sub Main( )
Console.WriteLine( _
"This example of the TimeSpan( Long ) constructor " & _
vbCrLf & "generates the following output." & vbCrLf )
Console.WriteLine( "{0,-33}{1,16}", "Constructor", "Value" )
Console.WriteLine( "{0,-33}{1,16}", "-----------", "-----" )
CreateTimeSpan( 1 )
CreateTimeSpan( 999999 )
CreateTimeSpan( -1000000000000 )
CreateTimeSpan( 18012202000000 )
CreateTimeSpan( 999999999999999999 )
CreateTimeSpan( 1000000000000000000 )
End Sub
End Module
' This example of the TimeSpan( Long ) constructor
' generates the following output.
'
' Constructor Value
' ----------- -----
' TimeSpan( 1 ) 00:00:00.0000001
' TimeSpan( 999999 ) 00:00:00.0999999
' TimeSpan( -1000000000000 ) -1.03:46:40
' TimeSpan( 18012202000000 ) 20.20:20:20.2000000
' TimeSpan( 999999999999999999 ) 1157407.09:46:39.9999999
' TimeSpan( 1000000000000000000 ) 1157407.09:46:40
// Example of the TimeSpan( long ) constructor.
using System;
class TimeSpanCtorLDemo
{
// Create a TimeSpan object and display its value.
static void CreateTimeSpan( long ticks )
{
TimeSpan elapsedTime = new TimeSpan( ticks );
// Format the constructor for display.
string ctor = String.Format( "TimeSpan( {0} )", ticks );
// Pad the end of a TimeSpan string with spaces if
// it does not contain milliseconds.
string elapsedStr = elapsedTime.ToString( );
int pointIndex = elapsedStr.IndexOf( ':' );
pointIndex = elapsedStr.IndexOf( '.', pointIndex );
if( pointIndex < 0 ) elapsedStr += " ";
// Display the constructor and its value.
Console.WriteLine( "{0,-33}{1,24}", ctor, elapsedStr );
}
static void Main( )
{
Console.WriteLine(
"This example of the TimeSpan( long ) constructor " +
"\ngenerates the following output.\n" );
Console.WriteLine( "{0,-33}{1,16}", "Constructor", "Value" );
Console.WriteLine( "{0,-33}{1,16}", "-----------", "-----" );
CreateTimeSpan( 1 );
CreateTimeSpan( 999999 );
CreateTimeSpan( -1000000000000 );
CreateTimeSpan( 18012202000000 );
CreateTimeSpan( 999999999999999999 );
CreateTimeSpan( 1000000000000000000 );
}
}
/*
This example of the TimeSpan( long ) constructor
generates the following output.
Constructor Value
----------- -----
TimeSpan( 1 ) 00:00:00.0000001
TimeSpan( 999999 ) 00:00:00.0999999
TimeSpan( -1000000000000 ) -1.03:46:40
TimeSpan( 18012202000000 ) 20.20:20:20.2000000
TimeSpan( 999999999999999999 ) 1157407.09:46:39.9999999
TimeSpan( 1000000000000000000 ) 1157407.09:46:40
*/
// Example of the TimeSpan( __int64 ) constructor.
using namespace System;
// Create a TimeSpan object and display its value.
void CreateTimeSpan( __int64 ticks )
{
TimeSpan elapsedTime = TimeSpan(ticks);
// Format the constructor for display.
String^ ctor = String::Format( "TimeSpan( {0} )", ticks );
// Pad the end of a TimeSpan string with spaces if
// it does not contain milliseconds.
String^ elapsedStr = elapsedTime.ToString();
int pointIndex = elapsedStr->IndexOf( ':' );
pointIndex = elapsedStr->IndexOf( '.', pointIndex );
if ( pointIndex < 0 )
elapsedStr = String::Concat( elapsedStr, " " );
// Display the constructor and its value.
Console::WriteLine( "{0,-33}{1,24}", ctor, elapsedStr );
}
int main()
{
Console::WriteLine( "This example of the TimeSpan( __int64 ) constructor "
"\ngenerates the following output.\n" );
Console::WriteLine( "{0,-33}{1,16}", "Constructor", "Value" );
Console::WriteLine( "{0,-33}{1,16}", "-----------", "-----" );
CreateTimeSpan( 1 );
CreateTimeSpan( 999999 );
CreateTimeSpan( -1000000000000 );
CreateTimeSpan( 18012202000000 );
CreateTimeSpan( 999999999999999999 );
CreateTimeSpan( 1000000000000000000 );
}
/*
This example of the TimeSpan( __int64 ) constructor
generates the following output.
Constructor Value
----------- -----
TimeSpan( 1 ) 00:00:00.0000001
TimeSpan( 999999 ) 00:00:00.0999999
TimeSpan( -1000000000000 ) -1.03:46:40
TimeSpan( 18012202000000 ) 20.20:20:20.2000000
TimeSpan( 999999999999999999 ) 1157407.09:46:39.9999999
TimeSpan( 1000000000000000000 ) 1157407.09:46:40
*/
// Example of the TimeSpan( long ) constructor.
import System.*;
class TimeSpanCtorLDemo
{
// Create a TimeSpan object and display its value.
static void CreateTimeSpan(long ticks)
{
TimeSpan elapsedTime = new TimeSpan(ticks);
// Format the constructor for display.
String ctor = String.Format("TimeSpan( {0} )", String.valueOf(ticks));
// Pad the end of a TimeSpan string with spaces if
// it does not contain milliseconds.
String elapsedStr = elapsedTime.ToString();
int pointIndex = elapsedStr.IndexOf(':');
pointIndex = elapsedStr.IndexOf('.', pointIndex);
if (pointIndex < 0) {
elapsedStr += " ";
}
// Display the constructor and its value.
Console.WriteLine("{0,-33}{1,24}", ctor, elapsedStr);
} //CreateTimeSPan
public static void main(String[] args)
{
Console.WriteLine(("This example of the TimeSpan( long ) constructor "
+ "\ngenerates the following output.\n"));
Console.WriteLine("{0,-33}{1,16}", "Constructor", "Value");
Console.WriteLine("{0,-33}{1,16}", "-----------", "-----");
CreateTimeSpan(1);
CreateTimeSpan(999999);
CreateTimeSpan(-1000000000000L);
CreateTimeSpan(18012202000000L);
CreateTimeSpan(999999999999999999L);
CreateTimeSpan(1000000000000000000L);
} //main
} //TimeSpanCtorLDemo
/*
This example of the TimeSpan( long ) constructor
generates the following output.
Constructor Value
----------- -----
TimeSpan( 1 ) 00:00:00.0000001
TimeSpan( 999999 ) 00:00:00.0999999
TimeSpan( -1000000000000 ) -1.03:46:40
TimeSpan( 18012202000000 ) 20.20:20:20.2000000
TimeSpan( 999999999999999999 ) 1157407.09:46:39.9999999
TimeSpan( 1000000000000000000 ) 1157407.09:46:40
*/
Plattformen
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
.NET Compact Framework
Unterstützt in: 2.0, 1.0
Siehe auch
Referenz
TimeSpan-Struktur
TimeSpan-Member
System-Namespace
Int64-Struktur