TimeSpan-Konstruktor (Int32, Int32, Int32, Int32, Int32)
Initialisiert eine neue TimeSpan mit der angegebenen Anzahl von Tagen, Stunden, Minuten, Sekunden und Millisekunden.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
Public Sub New ( _
days As Integer, _
hours As Integer, _
minutes As Integer, _
seconds As Integer, _
milliseconds As Integer _
)
'Usage
Dim days As Integer
Dim hours As Integer
Dim minutes As Integer
Dim seconds As Integer
Dim milliseconds As Integer
Dim instance As New TimeSpan(days, hours, minutes, seconds, milliseconds)
public TimeSpan (
int days,
int hours,
int minutes,
int seconds,
int milliseconds
)
public:
TimeSpan (
int days,
int hours,
int minutes,
int seconds,
int milliseconds
)
public TimeSpan (
int days,
int hours,
int minutes,
int seconds,
int milliseconds
)
public function TimeSpan (
days : int,
hours : int,
minutes : int,
seconds : int,
milliseconds : int
)
Parameter
- days
Anzahl der Tage.
- hours
Anzahl der Stunden.
- minutes
Anzahl der Minuten.
- seconds
Anzahl der Sekunden.
- milliseconds
Anzahl der Millisekunden.
Ausnahmen
Ausnahmetyp | Bedingung |
---|---|
Die Parameter geben einen TimeSpan-Wert an, der kleiner als MinValue oder größer als MaxValue ist. |
Hinweise
Die angegebenen days, hours, minutes, seconds und milliseconds werden in Ticks konvertiert, und die Instanz wird mit diesem Wert initialisiert.
Beispiel
Im folgenden Codebeispiel werden verschiedene TimeSpan-Objekte mithilfe der Konstruktorüberladung erstellt, die eine TimeSpan mit einer angegebenen Anzahl von Tagen, Stunden, Minuten, Sekunden und Millisekunden initialisiert.
' Example of the
' TimeSpan( Integer, Integer, Integer, Integer, Integer ) constructor.
Imports System
Imports Microsoft.VisualBasic
Module TimeSpanCtorIIIIIDemo
' Create a TimeSpan object and display its value.
Sub CreateTimeSpan( days As Integer, hours As Integer, _
minutes As Integer, seconds As Integer, millisec As Integer )
Dim elapsedTime As New TimeSpan( _
days, hours, minutes, seconds, millisec )
' Format the constructor for display.
Dim ctor As String = _
String.Format( "TimeSpan( {0}, {1}, {2}, {3}, {4} )", _
days, hours, minutes, seconds, millisec )
' Display the constructor and its value.
Console.WriteLine( "{0,-48}{1,24}", _
ctor, elapsedTime.ToString( ) )
End Sub
Sub Main( )
Console.WriteLine( _
"This example of the " & vbCrLf & _
"TimeSpan( Integer, Integer, " & _
"Integer, Integer, Integer ) " & vbCrLf & _
"constructor generates the following output." & vbCrLf )
Console.WriteLine( "{0,-48}{1,16}", "Constructor", "Value" )
Console.WriteLine( "{0,-48}{1,16}", "-----------", "-----" )
CreateTimeSpan( 10, 20, 30, 40, 50 )
CreateTimeSpan( -10, 20, 30, 40, 50 )
CreateTimeSpan( 0, 0, 0, 0, 937840050 )
CreateTimeSpan( 1111, 2222, 3333, 4444, 5555 )
CreateTimeSpan( 1111, -2222, -3333, -4444, -5555 )
CreateTimeSpan( 99999, 99999, 99999, 99999, 99999 )
End Sub
End Module
' This example of the
' TimeSpan( Integer, Integer, Integer, Integer, Integer )
' constructor generates the following output.
'
' Constructor Value
' ----------- -----
' TimeSpan( 10, 20, 30, 40, 50 ) 10.20:30:40.0500000
' TimeSpan( -10, 20, 30, 40, 50 ) -9.03:29:19.9500000
' TimeSpan( 0, 0, 0, 0, 937840050 ) 10.20:30:40.0500000
' TimeSpan( 1111, 2222, 3333, 4444, 5555 ) 1205.22:47:09.5550000
' TimeSpan( 1111, -2222, -3333, -4444, -5555 ) 1016.01:12:50.4450000
' TimeSpan( 99999, 99999, 99999, 99999, 99999 ) 104236.05:27:18.9990000
// Example of the TimeSpan( int, int, int, int, int ) constructor.
using System;
class TimeSpanCtorIIIIIDemo
{
// Create a TimeSpan object and display its value.
static void CreateTimeSpan( int days, int hours,
int minutes, int seconds, int millisec )
{
TimeSpan elapsedTime = new TimeSpan(
days, hours, minutes, seconds, millisec );
// Format the constructor for display.
string ctor =
String.Format( "TimeSpan( {0}, {1}, {2}, {3}, {4} )",
days, hours, minutes, seconds, millisec);
// Display the constructor and its value.
Console.WriteLine( "{0,-48}{1,24}",
ctor, elapsedTime.ToString( ) );
}
static void Main( )
{
Console.WriteLine(
"This example of the " +
"TimeSpan( int, int, int, int, int ) " +
"\nconstructor generates the following output.\n" );
Console.WriteLine( "{0,-48}{1,16}", "Constructor", "Value" );
Console.WriteLine( "{0,-48}{1,16}", "-----------", "-----" );
CreateTimeSpan( 10, 20, 30, 40, 50 );
CreateTimeSpan( -10, 20, 30, 40, 50 );
CreateTimeSpan( 0, 0, 0, 0, 937840050 );
CreateTimeSpan( 1111, 2222, 3333, 4444, 5555 );
CreateTimeSpan( 1111, -2222, -3333, -4444, -5555 );
CreateTimeSpan( 99999, 99999, 99999, 99999, 99999 );
}
}
/*
This example of the TimeSpan( int, int, int, int, int )
constructor generates the following output.
Constructor Value
----------- -----
TimeSpan( 10, 20, 30, 40, 50 ) 10.20:30:40.0500000
TimeSpan( -10, 20, 30, 40, 50 ) -9.03:29:19.9500000
TimeSpan( 0, 0, 0, 0, 937840050 ) 10.20:30:40.0500000
TimeSpan( 1111, 2222, 3333, 4444, 5555 ) 1205.22:47:09.5550000
TimeSpan( 1111, -2222, -3333, -4444, -5555 ) 1016.01:12:50.4450000
TimeSpan( 99999, 99999, 99999, 99999, 99999 ) 104236.05:27:18.9990000
*/
// Example of the TimeSpan( int, int, int, int, int ) constructor.
using namespace System;
// Create a TimeSpan object and display its value.
void CreateTimeSpan( int days, int hours, int minutes, int seconds, int millisec )
{
TimeSpan elapsedTime = TimeSpan(days,hours,minutes,seconds,millisec);
// Format the constructor for display.
array<Object^>^boxedParams = gcnew array<Object^>(5);
boxedParams[ 0 ] = days;
boxedParams[ 1 ] = hours;
boxedParams[ 2 ] = minutes;
boxedParams[ 3 ] = seconds;
boxedParams[ 4 ] = millisec;
String^ ctor = String::Format( "TimeSpan( {0}, {1}, {2}, {3}, {4} )", boxedParams );
// Display the constructor and its value.
Console::WriteLine( "{0,-48}{1,24}", ctor, elapsedTime.ToString() );
}
int main()
{
Console::WriteLine( "This example of the TimeSpan( int, int, int, int, int ) "
"\nconstructor generates the following output.\n" );
Console::WriteLine( "{0,-48}{1,16}", "Constructor", "Value" );
Console::WriteLine( "{0,-48}{1,16}", "-----------", "-----" );
CreateTimeSpan( 10, 20, 30, 40, 50 );
CreateTimeSpan( -10, 20, 30, 40, 50 );
CreateTimeSpan( 0, 0, 0, 0, 937840050 );
CreateTimeSpan( 1111, 2222, 3333, 4444, 5555 );
CreateTimeSpan( 1111, -2222, -3333, -4444, -5555 );
CreateTimeSpan( 99999, 99999, 99999, 99999, 99999 );
}
/*
This example of the TimeSpan( int, int, int, int, int )
constructor generates the following output.
Constructor Value
----------- -----
TimeSpan( 10, 20, 30, 40, 50 ) 10.20:30:40.0500000
TimeSpan( -10, 20, 30, 40, 50 ) -9.03:29:19.9500000
TimeSpan( 0, 0, 0, 0, 937840050 ) 10.20:30:40.0500000
TimeSpan( 1111, 2222, 3333, 4444, 5555 ) 1205.22:47:09.5550000
TimeSpan( 1111, -2222, -3333, -4444, -5555 ) 1016.01:12:50.4450000
TimeSpan( 99999, 99999, 99999, 99999, 99999 ) 104236.05:27:18.9990000
*/
// Example of the TimeSpan( int, int, int, int, int ) constructor.
import System.*;
class TimeSpanCtorIIIIIDemo
{
// Create a TimeSpan object and display its value.
static void CreateTimeSpan(int days, int hours, int minutes,
int seconds, int millisec)
{
TimeSpan elapsedTime = new TimeSpan(days, hours, minutes,
seconds, millisec);
// Format the constructor for display.
String ctor = String.Format("TimeSpan( {0}, {1}, {2}, {3}, {4} )",
new Object[] { (System.Int32)days, (System.Int32)hours,
(System.Int32)minutes, (System.Int32)seconds,
(System.Int32)millisec });
// Display the constructor and its value.
Console.WriteLine("{0,-48}{1,24}", ctor, elapsedTime.ToString());
} //CreateTimeSpan
public static void main(String[] args)
{
Console.WriteLine(("This example of the "
+ "TimeSpan( int, int, int, int, int ) "
+ "\nconstructor generates the following output.\n"));
Console.WriteLine("{0,-48}{1,16}", "Constructor", "Value");
Console.WriteLine("{0,-48}{1,16}", "-----------", "-----");
CreateTimeSpan(10, 20, 30, 40, 50);
CreateTimeSpan(-10, 20, 30, 40, 50);
CreateTimeSpan(0, 0, 0, 0, 937840050);
CreateTimeSpan(1111, 2222, 3333, 4444, 5555);
CreateTimeSpan(1111, -2222, -3333, -4444, -5555);
CreateTimeSpan(99999, 99999, 99999, 99999, 99999);
} //main
} //TimeSpanCtorIIIIIDemo
/*
This example of the TimeSpan( int, int, int, int, int )
constructor generates the following output.
Constructor Value
----------- -----
TimeSpan( 10, 20, 30, 40, 50 ) 10.20:30:40.0500000
TimeSpan( -10, 20, 30, 40, 50 ) -9.03:29:19.9500000
TimeSpan( 0, 0, 0, 0, 937840050 ) 10.20:30:40.0500000
TimeSpan( 1111, 2222, 3333, 4444, 5555 ) 1205.22:47:09.5550000
TimeSpan( 1111, -2222, -3333, -4444, -5555 ) 1016.01:12:50.4450000
TimeSpan( 99999, 99999, 99999, 99999, 99999 ) 104236.05:27:18.9990000
*/
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