Freigeben über


TimeSpan-Konstruktor (Int32, Int32, Int32, Int32)

Initialisiert eine neue TimeSpan mit der angegebenen Anzahl von Tagen, Stunden, Minuten und Sekunden.

Namespace: System
Assembly: mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Sub New ( _
    days As Integer, _
    hours As Integer, _
    minutes As Integer, _
    seconds As Integer _
)
'Usage
Dim days As Integer
Dim hours As Integer
Dim minutes As Integer
Dim seconds As Integer

Dim instance As New TimeSpan(days, hours, minutes, seconds)
public TimeSpan (
    int days,
    int hours,
    int minutes,
    int seconds
)
public:
TimeSpan (
    int days, 
    int hours, 
    int minutes, 
    int seconds
)
public TimeSpan (
    int days, 
    int hours, 
    int minutes, 
    int seconds
)
public function TimeSpan (
    days : int, 
    hours : int, 
    minutes : int, 
    seconds : int
)

Parameter

  • days
    Anzahl der Tage.
  • hours
    Anzahl der Stunden.
  • minutes
    Anzahl der Minuten.
  • seconds
    Anzahl der Sekunden.

Ausnahmen

Ausnahmetyp Bedingung

ArgumentOutOfRangeException

Die Parameter geben einen TimeSpan-Wert an, der kleiner als MinValue oder größer als MaxValue ist.

Hinweise

Die angegebenen days, hours, minutes und seconds 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 und Sekunden initialisiert.

' Example of the
' TimeSpan( Integer, Integer, Integer, Integer ) constructor.
Imports System
Imports Microsoft.VisualBasic

Module TimeSpanCtorIIIIDemo

    ' Create a TimeSpan object and display its value.
    Sub CreateTimeSpan( days As Integer, hours As Integer, _
        minutes As Integer, seconds As Integer )

        Dim elapsedTime As New TimeSpan( _
            days, hours, minutes, seconds )

        ' Format the constructor for display.
        Dim ctor AS String = _
            String.Format( "TimeSpan( {0}, {1}, {2}, {3} )", _
                days, hours, minutes, seconds )

        ' Display the constructor and its value.
        Console.WriteLine( "{0,-44}{1,16}", _
            ctor, elapsedTime.ToString( ) )
    End Sub
    
    Sub Main( )

        Console.WriteLine( _
            "This example of the " & vbCrLf & "TimeSpan( " & _
            "Integer, Integer, Integer, Integer ) " & vbCrLf & _
            "constructor generates the following output." & vbCrLf )
        Console.WriteLine( "{0,-44}{1,16}", "Constructor", "Value" )
        Console.WriteLine( "{0,-44}{1,16}", "-----------", "-----" )

        CreateTimeSpan( 10, 20, 30, 40 )
        CreateTimeSpan( -10, 20, 30, 40 )
        CreateTimeSpan( 0, 0, 0, 937840 )
        CreateTimeSpan( 1000, 2000, 3000, 4000 )
        CreateTimeSpan( 1000, -2000, -3000, -4000 )
        CreateTimeSpan( 999999, 999999, 999999, 999999 )
    End Sub 
End Module 

' This example of the
' TimeSpan( Integer, Integer, Integer, Integer )
' constructor generates the following output.
' 
' Constructor                                            Value
' -----------                                            -----
' TimeSpan( 10, 20, 30, 40 )                       10.20:30:40
' TimeSpan( -10, 20, 30, 40 )                      -9.03:29:20
' TimeSpan( 0, 0, 0, 937840 )                      10.20:30:40
' TimeSpan( 1000, 2000, 3000, 4000 )             1085.11:06:40
' TimeSpan( 1000, -2000, -3000, -4000 )           914.12:53:20
' TimeSpan( 999999, 999999, 999999, 999999 )   992661.08:57:23
// Example of the TimeSpan( int, int, int, int ) constructor.
using System;

class TimeSpanCtorIIIIDemo
{
    // Create a TimeSpan object and display its value.
    static void CreateTimeSpan( int days, int hours, 
        int minutes, int seconds )
    {
        TimeSpan elapsedTime = 
            new TimeSpan( days, hours, minutes, seconds );

        // Format the constructor for display.
        string ctor = 
            String.Format( "TimeSpan( {0}, {1}, {2}, {3} )", 
                days, hours, minutes, seconds);

        // Display the constructor and its value.
        Console.WriteLine( "{0,-44}{1,16}", 
            ctor, elapsedTime.ToString( ) );
    }
    
    static void Main( )
    {
        Console.WriteLine( 
            "This example of the TimeSpan( int, int, int, int ) " +
            "\nconstructor generates the following output.\n" );
        Console.WriteLine( "{0,-44}{1,16}", "Constructor", "Value" );
        Console.WriteLine( "{0,-44}{1,16}", "-----------", "-----" );

        CreateTimeSpan( 10, 20, 30, 40 );
        CreateTimeSpan( -10, 20, 30, 40 );
        CreateTimeSpan( 0, 0, 0, 937840 );
        CreateTimeSpan( 1000, 2000, 3000, 4000 );
        CreateTimeSpan( 1000, -2000, -3000, -4000 );
        CreateTimeSpan( 999999, 999999, 999999, 999999 );
    } 
} 

/*
This example of the TimeSpan( int, int, int, int )
constructor generates the following output.

Constructor                                            Value
-----------                                            -----
TimeSpan( 10, 20, 30, 40 )                       10.20:30:40
TimeSpan( -10, 20, 30, 40 )                      -9.03:29:20
TimeSpan( 0, 0, 0, 937840 )                      10.20:30:40
TimeSpan( 1000, 2000, 3000, 4000 )             1085.11:06:40
TimeSpan( 1000, -2000, -3000, -4000 )           914.12:53:20
TimeSpan( 999999, 999999, 999999, 999999 )   992661.08:57:23
*/
// Example of the TimeSpan( 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 )
{
   TimeSpan elapsedTime = TimeSpan(days,hours,minutes,seconds);
   
   // Format the constructor for display.
   array<Object^>^boxedParams = gcnew array<Object^>(4);
   boxedParams[ 0 ] = days;
   boxedParams[ 1 ] = hours;
   boxedParams[ 2 ] = minutes;
   boxedParams[ 3 ] = seconds;
   String^ ctor = String::Format( "TimeSpan( {0}, {1}, {2}, {3} )", boxedParams );
   
   // Display the constructor and its value.
   Console::WriteLine( "{0,-44}{1,16}", ctor, elapsedTime.ToString() );
}

int main()
{
   Console::WriteLine( "This example of the TimeSpan( int, int, int, int ) "
   "\nconstructor generates the following output.\n" );
   Console::WriteLine( "{0,-44}{1,16}", "Constructor", "Value" );
   Console::WriteLine( "{0,-44}{1,16}", "-----------", "-----" );
   CreateTimeSpan( 10, 20, 30, 40 );
   CreateTimeSpan(  -10, 20, 30, 40 );
   CreateTimeSpan( 0, 0, 0, 937840 );
   CreateTimeSpan( 1000, 2000, 3000, 4000 );
   CreateTimeSpan( 1000, -2000, -3000, -4000 );
   CreateTimeSpan( 999999, 999999, 999999, 999999 );
}

/*
This example of the TimeSpan( int, int, int, int )
constructor generates the following output.

Constructor                                            Value
-----------                                            -----
TimeSpan( 10, 20, 30, 40 )                       10.20:30:40
TimeSpan( -10, 20, 30, 40 )                      -9.03:29:20
TimeSpan( 0, 0, 0, 937840 )                      10.20:30:40
TimeSpan( 1000, 2000, 3000, 4000 )             1085.11:06:40
TimeSpan( 1000, -2000, -3000, -4000 )           914.12:53:20
TimeSpan( 999999, 999999, 999999, 999999 )   992661.08:57:23
*/
// Example of the TimeSpan( int, int, int, int ) constructor.
import System.*;

class TimeSpanCtorIIIIDemo
{
    // Create a TimeSpan object and display its value.
    static void CreateTimeSpan(int days, int hours, int minutes, int seconds)
    {
        TimeSpan elapsedTime = new TimeSpan(days, hours, minutes, seconds);

        // Format the constructor for display.
        String ctor = String.Format("TimeSpan( {0}, {1}, {2}, {3} )",
            new Object[] { (System.Int32)days, (System.Int32)hours,
            (System.Int32)minutes, (System.Int32)seconds });

        // Display the constructor and its value.
        Console.WriteLine("{0,-44}{1,16}", ctor, elapsedTime.ToString());
    } //CreateTimeSpan

    public static void main(String[] args)
    {
        Console.WriteLine(("This example of the TimeSpan(int, int, int, int )"
            + "\nconstructor generates the following output.\n"));
        Console.WriteLine("{0,-44}{1,16}", "Constructor", "Value");
        Console.WriteLine("{0,-44}{1,16}", "-----------", "-----");
        CreateTimeSpan(10, 20, 30, 40);
        CreateTimeSpan(-10, 20, 30, 40);
        CreateTimeSpan(0, 0, 0, 937840);
        CreateTimeSpan(1000, 2000, 3000, 4000);
        CreateTimeSpan(1000, -2000, -3000, -4000);
        CreateTimeSpan(999999, 999999, 999999, 999999);
    } //main
} //TimeSpanCtorIIIIDemo

/*
This example of the TimeSpan( int, int, int, int )
constructor generates the following output.

Constructor                                            Value
-----------                                            -----
TimeSpan( 10, 20, 30, 40 )                       10.20:30:40
TimeSpan( -10, 20, 30, 40 )                      -9.03:29:20
TimeSpan( 0, 0, 0, 937840 )                      10.20:30:40
TimeSpan( 1000, 2000, 3000, 4000 )             1085.11:06:40
TimeSpan( 1000, -2000, -3000, -4000 )           914.12:53:20
TimeSpan( 999999, 999999, 999999, 999999 )   992661.08:57:23
*/

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