C# TimeSpan構造函數代碼示例- 純淨天空

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

本文整理匯總了C#中System.TimeSpan.TimeSpan構造函數的典型用法代碼示例。

如果您正苦於以下問題:C# TimeSpan構造函數的具體用法?C# TimeSpan怎麽用? 當前位置:首頁>>代碼示例>>C#>>正文 本文整理匯總了C#中System.TimeSpan.TimeSpan構造函數的典型用法代碼示例。

如果您正苦於以下問題:C#TimeSpan構造函數的具體用法?C#TimeSpan怎麽用?C#TimeSpan使用的例子?那麽恭喜您,這裏精選的構造函數代碼示例或許可以為您提供幫助。

您也可以進一步了解該構造函數所在類System.TimeSpan的用法示例。

在下文中一共展示了TimeSpan構造函數的4個代碼示例,這些例子默認根據受歡迎程度排序。

您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於我們的係統推薦出更棒的C#代碼示例。

示例1:CreateTimeSpan ​點讚15 ​ //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); } }開發者ID:.NET開發者,項目名稱:System,代碼行數:41,代碼來源:TimeSpan輸出: 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 示例2:CreateTimeSpan ​點讚15 ​ //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); } }開發者ID:.NET開發者,項目名稱:System,代碼行數:37,代碼來源:TimeSpan輸出: 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 示例3:CreateTimeSpan ​點讚14 ​ //引入命名空間 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); } }開發者ID:.NET開發者,項目名稱:System,代碼行數:35,代碼來源:TimeSpan輸出: 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 示例4:CreateTimeSpan ​點讚12 ​ //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); } }開發者ID:.NET開發者,項目名稱:System,代碼行數:39,代碼來源:TimeSpan輸出: 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 注:本文中的System.TimeSpan.TimeSpan構造函數示例整理自Github/MSDocs等源碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。

相關方法 TimeSpan.TimeSpan() TimeSpan.MaxValue TimeSpan.MinValue TimeSpan.TicksPerDay TimeSpan.TicksPerHour TimeSpan.TicksPerMillisecond TimeSpan.TicksPerMinute TimeSpan.TicksPerSecond TimeSpan.Zero TimeSpan.Days TimeSpan.Hours TimeSpan.Milliseconds TimeSpan.Minutes TimeSpan.Seconds TimeSpan.Ticks TimeSpan.TotalDays TimeSpan.TotalHours TimeSpan.TotalMilliseconds TimeSpan.TotalMinutes TimeSpan.TotalSeconds TimeSpan.Add() TimeSpan.Compare() TimeSpan.CompareTo() TimeSpan.Duration() TimeSpan.Equals() TimeSpan.FromDays() TimeSpan.FromHours() TimeSpan.FromMilliseconds() TimeSpan.FromMinutes() TimeSpan.FromSeconds() TimeSpan.FromTicks() TimeSpan.GetHashCode() TimeSpan.Negate() TimeSpan.Parse() TimeSpan.ParseExact() TimeSpan.Subtract() TimeSpan.ToString() TimeSpan.TryParse() TimeSpan.TryParseExact() TimeSpan.Addition() TimeSpan.Equality() TimeSpan.GreaterThan() TimeSpan.GreaterThanOrEqual() TimeSpan.Inequality() TimeSpan.LessThan() TimeSpan.LessThanOrEqual() TimeSpan.Subtraction() TimeSpan.UnaryNegation() TimeSpan.UnaryPlus()



請為這篇文章評分?