TimeSpan 建構函式(System)

文章推薦指數: 80 %
投票人數:10人

將TimeSpan 結構的新執行個體初始化為指定的時數、分鐘數和秒數。

public: TimeSpan(int hours, int minutes, int seconds);. C# 複製. 跳到主要內容 已不再支援此瀏覽器。

請升級至MicrosoftEdge,以利用最新功能、安全性更新和技術支援。

下載MicrosoftEdge 其他資訊 目錄 結束焦點模式 語言 閱讀英文 儲存 編輯 共用 Twitter LinkedIn Facebook 電子郵件 WeChat 目錄 語言 語言 閱讀英文 儲存 目錄 閱讀英文 儲存 編輯 Twitter LinkedIn Facebook 電子郵件 WeChat 目錄 TimeSpan建構函式 參考 此頁面有所助益嗎? Yes No 還有其他意見反應嗎? 系統會將意見反應傳送給Microsoft:按下[提交]按鈕,您的意見反應將用來改善Microsoft產品和服務。

隱私權原則。

送出 謝謝。

定義 命名空間: System 組件:System.Runtime.dll 組件:mscorlib.dll 組件:netstandard.dll 重要 部分資訊涉及發行前產品,在發行之前可能會有大幅修改。

Microsoft對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。

初始化TimeSpan結構的新執行個體。

本文內容 多載 TimeSpan(Int64) 將TimeSpan結構的新執行個體初始化為刻度的指定數目。

TimeSpan(Int32,Int32,Int32) 將TimeSpan結構的新執行個體初始化為指定的時數、分鐘數和秒數。

TimeSpan(Int32,Int32,Int32,Int32) 將TimeSpan結構的新執行個體初始化為指定的天數、時數、分鐘數和秒數。

TimeSpan(Int32,Int32,Int32,Int32,Int32) 將TimeSpan結構的新執行個體初始化為指定的天數、時數、分鐘數、秒數和毫秒數。

TimeSpan(Int64) 將TimeSpan結構的新執行個體初始化為刻度的指定數目。

public: TimeSpan(longticks); publicTimeSpan(longticks); newTimeSpan:int64->TimeSpan PublicSubNew(ticksAsLong) 參數 ticks Int64 以100奈秒為單位所表示的時段。

範例 下列範例TimeSpan會使用會將初始化TimeSpan為指定刻度數的函式多載,來建立數個物件。

//ExampleoftheTimeSpan(__int64)constructor. usingnamespaceSystem; //CreateaTimeSpanobjectanddisplayitsvalue. voidCreateTimeSpan(__int64ticks) { TimeSpanelapsedTime=TimeSpan(ticks); //Formattheconstructorfordisplay. String^ctor=String::Format("TimeSpan({0})",ticks); //PadtheendofaTimeSpanstringwithspacesif //itdoesnotcontainmilliseconds. String^elapsedStr=elapsedTime.ToString(); intpointIndex=elapsedStr->IndexOf(':'); pointIndex=elapsedStr->IndexOf('.',pointIndex); if(pointIndex<0) elapsedStr=String::Concat(elapsedStr,""); //Displaytheconstructoranditsvalue. Console::WriteLine("{0,-33}{1,24}",ctor,elapsedStr); } intmain() { Console::WriteLine("ThisexampleoftheTimeSpan(__int64)constructor" "\ngeneratesthefollowingoutput.\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); } /* ThisexampleoftheTimeSpan(__int64)constructor generatesthefollowingoutput. ConstructorValue ---------------- 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 */ //ExampleoftheTimeSpan(long)constructor. usingSystem; classTimeSpanCtorLDemo { //CreateaTimeSpanobjectanddisplayitsvalue. staticvoidCreateTimeSpan(longticks) { TimeSpanelapsedTime=newTimeSpan(ticks); //Formattheconstructorfordisplay. stringctor=String.Format("TimeSpan({0})",ticks); //PadtheendofaTimeSpanstringwithspacesif //itdoesnotcontainmilliseconds. stringelapsedStr=elapsedTime.ToString(); intpointIndex=elapsedStr.IndexOf(':'); pointIndex=elapsedStr.IndexOf('.',pointIndex); if(pointIndex<0)elapsedStr+=""; //Displaytheconstructoranditsvalue. Console.WriteLine("{0,-33}{1,24}",ctor,elapsedStr); } staticvoidMain() { Console.WriteLine( "ThisexampleoftheTimeSpan(long)constructor"+ "\ngeneratesthefollowingoutput.\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); } } /* ThisexampleoftheTimeSpan(long)constructor generatesthefollowingoutput. ConstructorValue ---------------- 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 */ 'ExampleoftheTimeSpan(Long)constructor. ModuleTimeSpanCtorLDemo 'CreateaTimeSpanobjectanddisplayitsvalue. SubCreateTimeSpan(ticksAsLong) DimelapsedTimeAsNewTimeSpan(ticks) 'Formattheconstructorfordisplay. DimctorASString=_ String.Format("TimeSpan({0})",ticks) 'PadtheendofaTimeSpanstringwithspacesif 'itdoesnotcontainmilliseconds. DimelapsedStrAsString=elapsedTime.ToString() DimpointIndexAsInteger=elapsedStr.IndexOf(":"c) pointIndex=elapsedStr.IndexOf("."c,pointIndex) IfpointIndex<0ThenelapsedStr&="" 'Displaytheconstructoranditsvalue. Console.WriteLine("{0,-33}{1,24}",ctor,elapsedStr) EndSub SubMain() Console.WriteLine(_ "ThisexampleoftheTimeSpan(Long)constructor"&_ vbCrLf&"generatesthefollowingoutput."&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) EndSub EndModule 'ThisexampleoftheTimeSpan(Long)constructor 'generatesthefollowingoutput. ' 'ConstructorValue '---------------- '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 備註 單一刻度代表100毫微秒或110-百萬分之一秒秒。

以毫秒為單位的10000刻度。

另請參閱 Ticks 適用於 TimeSpan(Int32,Int32,Int32) 將TimeSpan結構的新執行個體初始化為指定的時數、分鐘數和秒數。

public: TimeSpan(inthours,intminutes,intseconds); publicTimeSpan(inthours,intminutes,intseconds); newTimeSpan:int*int*int->TimeSpan PublicSubNew(hoursAsInteger,minutesAsInteger,secondsAsInteger) 參數 hours Int32 時數。

minutes Int32 分鐘數。

seconds Int32 秒數。

例外狀況 ArgumentOutOfRangeException 這些參數會指定TimeSpan值小於MinValue或大於MaxValue。

範例 下列範例TimeSpan會使用會將初始化TimeSpan為指定時數、分鐘數和秒數的函式多載,來建立數個物件。

//ExampleoftheTimeSpan(int,int,int)constructor. usingnamespaceSystem; //CreateaTimeSpanobjectanddisplayitsvalue. staticvoidCreateTimeSpan(inthours,intminutes,intseconds) { TimeSpanelapsedTime=TimeSpan(hours,minutes,seconds); //Formattheconstructorfordisplay. String^ctor=String::Format("TimeSpan({0},{1},{2})",hours,minutes,seconds); //Displaytheconstructoranditsvalue. Console::WriteLine("{0,-37}{1,16}",ctor,elapsedTime.ToString()); } intmain() { Console::WriteLine("ThisexampleoftheTimeSpan(int,int,int)" "\nconstructorgeneratesthefollowingoutput.\n"); Console::WriteLine("{0,-37}{1,16}","Constructor","Value"); Console::WriteLine("{0,-37}{1,16}","-----------","-----"); CreateTimeSpan(10,20,30); CreateTimeSpan(-10,20,30); CreateTimeSpan(0,0,37230); CreateTimeSpan(1000,2000,3000); CreateTimeSpan(1000,-2000,-3000); CreateTimeSpan(999999,999999,999999); } /* ThisexampleoftheTimeSpan(int,int,int) constructorgeneratesthefollowingoutput. ConstructorValue ---------------- TimeSpan(10,20,30)10:20:30 TimeSpan(-10,20,30)-09:39:30 TimeSpan(0,0,37230)10:20:30 TimeSpan(1000,2000,3000)43.02:10:00 TimeSpan(1000,-2000,-3000)40.05:50:00 TimeSpan(999999,999999,999999)42372.15:25:39 */ //ExampleoftheTimeSpan(int,int,int)constructor. usingSystem; classTimeSpanCtorIIIDemo { //CreateaTimeSpanobjectanddisplayitsvalue. staticvoidCreateTimeSpan(inthours,intminutes, intseconds) { TimeSpanelapsedTime= newTimeSpan(hours,minutes,seconds); //Formattheconstructorfordisplay. stringctor=String.Format("TimeSpan({0},{1},{2})", hours,minutes,seconds); //Displaytheconstructoranditsvalue. Console.WriteLine("{0,-37}{1,16}", ctor,elapsedTime.ToString()); } staticvoidMain() { Console.WriteLine( "ThisexampleoftheTimeSpan(int,int,int)"+ "\nconstructorgeneratesthefollowingoutput.\n"); Console.WriteLine("{0,-37}{1,16}","Constructor","Value"); Console.WriteLine("{0,-37}{1,16}","-----------","-----"); CreateTimeSpan(10,20,30); CreateTimeSpan(-10,20,30); CreateTimeSpan(0,0,37230); CreateTimeSpan(1000,2000,3000); CreateTimeSpan(1000,-2000,-3000); CreateTimeSpan(999999,999999,999999); } } /* ThisexampleoftheTimeSpan(int,int,int) constructorgeneratesthefollowingoutput. ConstructorValue ---------------- TimeSpan(10,20,30)10:20:30 TimeSpan(-10,20,30)-09:39:30 TimeSpan(0,0,37230)10:20:30 TimeSpan(1000,2000,3000)43.02:10:00 TimeSpan(1000,-2000,-3000)40.05:50:00 TimeSpan(999999,999999,999999)42372.15:25:39 */ 'ExampleoftheTimeSpan(Integer,Integer,Integer)constructor. ModuleTimeSpanCtorIIIDemo 'CreateaTimeSpanobjectanddisplayitsvalue. SubCreateTimeSpan(hoursAsInteger,minutesAsInteger,_ secondsAsInteger) DimelapsedTimeAsNewTimeSpan(hours,minutes,seconds) 'Formattheconstructorfordisplay. DimctorASString=_ String.Format("TimeSpan({0},{1},{2})",_ hours,minutes,seconds) 'Displaytheconstructoranditsvalue. Console.WriteLine("{0,-37}{1,16}",_ ctor,elapsedTime.ToString()) EndSub SubMain() Console.WriteLine(_ "Thisexampleofthe"&_ "TimeSpan(Integer,Integer,Integer)"&vbCrLf&_ "constructorgeneratesthefollowingoutput."&vbCrLf) Console.WriteLine("{0,-37}{1,16}","Constructor","Value") Console.WriteLine("{0,-37}{1,16}","-----------","-----") CreateTimeSpan(10,20,30) CreateTimeSpan(-10,20,30) CreateTimeSpan(0,0,37230) CreateTimeSpan(1000,2000,3000) CreateTimeSpan(1000,-2000,-3000) CreateTimeSpan(999999,999999,999999) EndSub EndModule 'ThisexampleoftheTimeSpan(Integer,Integer,Integer) 'constructorgeneratesthefollowingoutput. ' 'ConstructorValue '---------------- 'TimeSpan(10,20,30)10:20:30 'TimeSpan(-10,20,30)-09:39:30 'TimeSpan(0,0,37230)10:20:30 'TimeSpan(1000,2000,3000)43.02:10:00 'TimeSpan(1000,-2000,-3000)40.05:50:00 'TimeSpan(999999,999999,999999)42372.15:25:39 備註 指定的hours、minutes和seconds會轉換成刻度,而該值會初始化這個實例。

另請參閱 Int64 適用於 TimeSpan(Int32,Int32,Int32,Int32) 將TimeSpan結構的新執行個體初始化為指定的天數、時數、分鐘數和秒數。

public: TimeSpan(intdays,inthours,intminutes,intseconds); publicTimeSpan(intdays,inthours,intminutes,intseconds); newTimeSpan:int*int*int*int->TimeSpan PublicSubNew(daysAsInteger,hoursAsInteger,minutesAsInteger,secondsAsInteger) 參數 days Int32 天數。

hours Int32 時數。

minutes Int32 分鐘數。

seconds Int32 秒數。

例外狀況 ArgumentOutOfRangeException 這些參數會指定TimeSpan值小於MinValue或大於MaxValue。

範例 下列範例TimeSpan會使用會將初始化TimeSpan為指定天數、小時、分鐘和秒數的函式多載,來建立數個物件。

usingnamespaceSystem; //CreateaTimeSpanobjectanddisplayitsvalue. voidCreateTimeSpan(intdays,inthours,intminutes,intseconds) { TimeSpanelapsedTime=TimeSpan(days,hours,minutes,seconds); //Formattheconstructorfordisplay. array^boxedParams=gcnewarray(4); boxedParams[0]=days; boxedParams[1]=hours; boxedParams[2]=minutes; boxedParams[3]=seconds; String^ctor=String::Format("TimeSpan({0},{1},{2},{3})",boxedParams); //Displaytheconstructoranditsvalue. Console::WriteLine("{0,-44}{1,16}",ctor,elapsedTime.ToString()); } intmain() { 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); } //Theexampledisplaysthefollowingoutput: //ConstructorValue //---------------- //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)1042371.15:25:39 usingSystem; classExample { //CreateaTimeSpanobjectanddisplayitsvalue. staticvoidCreateTimeSpan(intdays,inthours, intminutes,intseconds) { TimeSpanelapsedTime= newTimeSpan(days,hours,minutes,seconds); //Formattheconstructorfordisplay. stringctor= String.Format("TimeSpan({0},{1},{2},{3})", days,hours,minutes,seconds); //Displaytheconstructoranditsvalue. Console.WriteLine("{0,-44}{1,16}", ctor,elapsedTime.ToString()); } staticvoidMain() { 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); } } //Theexampledisplaysthefollowingoutput: //ConstructorValue //---------------- //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)1042371.15:25:39 ModuleExample 'CreateaTimeSpanobjectanddisplayitsvalue. SubCreateTimeSpan(daysAsInteger,hoursAsInteger,_ minutesAsInteger,secondsAsInteger) DimelapsedTimeAsNewTimeSpan(_ days,hours,minutes,seconds) 'Formattheconstructorfordisplay. DimctorASString=_ String.Format("TimeSpan({0},{1},{2},{3})",_ days,hours,minutes,seconds) 'Displaytheconstructoranditsvalue. Console.WriteLine("{0,-44}{1,16}",_ ctor,elapsedTime.ToString()) EndSub SubMain() 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) EndSub EndModule 'Theexamplegeneratesthefollowingoutput: 'ConstructorValue '---------------- '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)1042371.15:25:39 備註 指定的days、hours、minutes和seconds會轉換成刻度,而該值會初始化這個實例。

另請參閱 Int64 適用於 TimeSpan(Int32,Int32,Int32,Int32,Int32) 將TimeSpan結構的新執行個體初始化為指定的天數、時數、分鐘數、秒數和毫秒數。

public: TimeSpan(intdays,inthours,intminutes,intseconds,intmilliseconds); publicTimeSpan(intdays,inthours,intminutes,intseconds,intmilliseconds); newTimeSpan:int*int*int*int*int->TimeSpan PublicSubNew(daysAsInteger,hoursAsInteger,minutesAsInteger,secondsAsInteger,millisecondsAsInteger) 參數 days Int32 天數。

hours Int32 時數。

minutes Int32 分鐘數。

seconds Int32 秒數。

milliseconds Int32 毫秒數。

例外狀況 ArgumentOutOfRangeException 這些參數會指定TimeSpan值小於MinValue或大於MaxValue。

範例 下列範例TimeSpan會使用會將初始化TimeSpan為指定天數、小時、分鐘、秒和毫秒的函式多載,來建立數個物件。

//ExampleoftheTimeSpan(int,int,int,int,int)constructor. usingnamespaceSystem; //CreateaTimeSpanobjectanddisplayitsvalue. voidCreateTimeSpan(intdays,inthours,intminutes,intseconds,intmillisec) { TimeSpanelapsedTime=TimeSpan(days,hours,minutes,seconds,millisec); //Formattheconstructorfordisplay. array^boxedParams=gcnewarray(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); //Displaytheconstructoranditsvalue. Console::WriteLine("{0,-48}{1,24}",ctor,elapsedTime.ToString()); } intmain() { Console::WriteLine("ThisexampleoftheTimeSpan(int,int,int,int,int)" "\nconstructorgeneratesthefollowingoutput.\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); } /* ThisexampleoftheTimeSpan(int,int,int,int,int) constructorgeneratesthefollowingoutput. ConstructorValue ---------------- 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 */ //ExampleoftheTimeSpan(int,int,int,int,int)constructor. usingSystem; classTimeSpanCtorIIIIIDemo { //CreateaTimeSpanobjectanddisplayitsvalue. staticvoidCreateTimeSpan(intdays,inthours, intminutes,intseconds,intmillisec) { TimeSpanelapsedTime=newTimeSpan( days,hours,minutes,seconds,millisec); //Formattheconstructorfordisplay. stringctor= String.Format("TimeSpan({0},{1},{2},{3},{4})", days,hours,minutes,seconds,millisec); //Displaytheconstructoranditsvalue. Console.WriteLine("{0,-48}{1,24}", ctor,elapsedTime.ToString()); } staticvoidMain() { Console.WriteLine( "Thisexampleofthe"+ "TimeSpan(int,int,int,int,int)"+ "\nconstructorgeneratesthefollowingoutput.\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); } } /* ThisexampleoftheTimeSpan(int,int,int,int,int) constructorgeneratesthefollowingoutput. ConstructorValue ---------------- 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 */ 'Exampleofthe 'TimeSpan(Integer,Integer,Integer,Integer,Integer)constructor. ModuleTimeSpanCtorIIIIIDemo 'CreateaTimeSpanobjectanddisplayitsvalue. SubCreateTimeSpan(daysAsInteger,hoursAsInteger,_ minutesAsInteger,secondsAsInteger,millisecAsInteger) DimelapsedTimeAsNewTimeSpan(_ days,hours,minutes,seconds,millisec) 'Formattheconstructorfordisplay. DimctorAsString=_ String.Format("TimeSpan({0},{1},{2},{3},{4})",_ days,hours,minutes,seconds,millisec) 'Displaytheconstructoranditsvalue. Console.WriteLine("{0,-48}{1,24}",_ ctor,elapsedTime.ToString()) EndSub SubMain() Console.WriteLine(_ "Thisexampleofthe"&vbCrLf&_ "TimeSpan(Integer,Integer,"&_ "Integer,Integer,Integer)"&vbCrLf&_ "constructorgeneratesthefollowingoutput."&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) EndSub EndModule 'Thisexampleofthe 'TimeSpan(Integer,Integer,Integer,Integer,Integer) 'constructorgeneratesthefollowingoutput. ' 'ConstructorValue '---------------- '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 備註 指定的days、hours、minutes、seconds和milliseconds會轉換成刻度,而該值會初始化這個實例。

另請參閱 Int64 適用於 本文內容



請為這篇文章評分?