当前位置: 首页>>代码示例>>C#>>正文


C# TimeSpan.ToString方法代码示例

本文整理汇总了C#中TimeSpan.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# TimeSpan.ToString方法的具体用法?C# TimeSpan.ToString怎么用?C# TimeSpan.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TimeSpan的用法示例。


在下文中一共展示了TimeSpan.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: runTest

 public virtual bool runTest()
   {
   int iCountErrors = 0;
   int iCountTestcases = 0;
   Console.Error.WriteLine( strName + ": " + strTest + " runTest started..." );
   TimeSpan	ts;
   String		strDefTime = "00:00:00";
   long[]		lTicks = { 0L, 10000L, 1000*10000L, -1 };
   String[]	strResults =
   {
     "00:00:00",
     "00:00:00.0010000",
     "00:00:01",
     "-00:00:00.0000001",
   };
   do
     {
     Console.Error.WriteLine( "[]  Construct and verify TimeSpan objects" );
     try
       {
       for ( int ii = 0; ii < lTicks.Length; ++ii )
	 {
	 ++iCountTestcases;
	 ts = new TimeSpan( lTicks[ii] );
	 if ( String.Equals( ts.ToString(), strResults[ii] ) != true )
	   {
	   String strInfo = strTest + " error: ";
	   strInfo = strInfo + "Expected TimeSpan string <" + strResults[ii] + "> ";
	   strInfo = strInfo + "Returned TimeSpan string <" + ts.ToString() + "> ";
	   Console.WriteLine( strTest+ "E_101b: " + strInfo );
	   ++iCountErrors;
	   break;
	   }
	 }
       }
     catch (Exception ex)
       {
       Console.WriteLine( strTest+ "E_10001: Unexpected Exception: " + ex.ToString() );
       ++iCountErrors;
       break;
       }
     }
   while ( false );
   Console.Error.Write( strName );
   Console.Error.Write( ": " );
   if ( iCountErrors == 0 )
     {
     Console.Error.WriteLine( strTest + " iCountTestcases==" + iCountTestcases + " paSs" );
     return true;
     }
   else
     {
     System.String strFailMsg = null;
     Console.WriteLine( strTest+ strPath );
     Console.WriteLine( strTest+ "FAiL" );
     Console.Error.WriteLine( strTest + " iCountErrors==" + iCountErrors );
     return false;
     }
   }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:59,代码来源:co2902ctor_long.cs

示例2: FormatElapsed

    //--------------------------------------------------------------------------------------------

    static string FormatElapsed(TimeSpan dt)
        {
        StringBuilder result = new StringBuilder();
        if (dt.Days != 0)
            {
            result.Append(dt.ToString(@"%d"));
            result.Append(dt.Days <= 1 ? " day " : " days ");
            }
        result.Append(dt.ToString(@"hh\:mm\:ss\.ff"));
        return result.ToString();
        }
开发者ID:rgatkinson,项目名称:nadir,代码行数:13,代码来源:Output.cs

示例3: GetTimeZoneStringFromDouble

 public string GetTimeZoneStringFromDouble(double TimeZoneOffset, string TimeZoneName)
 {
     int hour = Convert.ToInt32(Math.Floor(TimeZoneOffset));
     int minute = Convert.ToInt32((TimeZoneOffset - hour) * 60.0);
     TimeSpan span = new TimeSpan(hour, minute, 0);
     string timezone_string = span.ToString().Remove(span.ToString().Length - 3) + ") " + TimeZoneName;
     if (hour >= 0)
         return "(GMT+" + timezone_string;
     else
         return "(GMT" + timezone_string;
 }
开发者ID:dcolonvizi,项目名称:ViziAppsPortal,代码行数:11,代码来源:TimeZones.cs

示例4: runTest

 public virtual bool runTest()
   {
   int iCountErrors = 0;
   int iCountTestcases = 0;
   Console.Error.WriteLine( strName + ": " + strTest + " runTest started..." );
   TimeSpan	ts;
   String		strDefTime = "00:00:00";
   do
     {
     ++iCountTestcases;
     Console.Error.WriteLine( "[]  Construct default TimeSpan object" );
     try
       {
       ts = new TimeSpan();
       if ( String.Equals( ts.ToString(), "00:00:00") != true )
	 {
	 String strInfo = strTest + " error: ";
	 strInfo = strInfo + "Expected TimeSpan string <00:00:00>";
	 strInfo = strInfo + "Returned TimeSpan string <"+ ts.ToString() + "> ";
	 Console.WriteLine( strTest+ "E_101b: " + strInfo );
	 ++iCountErrors;
	 break;
	 }
       }
     catch (Exception ex)
       {
       Console.WriteLine( strTest+ "E_10001: Unexpected Exception: " + ex.ToString() );
       ++iCountErrors;
       break;
       }
     }
   while ( false );
   Console.Error.Write( strName );
   Console.Error.Write( ": " );
   if ( iCountErrors == 0 )
     {
     Console.Error.WriteLine( strTest + " iCountTestcases==" + iCountTestcases + " paSs" );
     return true;
     }
   else
     {
     System.String strFailMsg = null;
     Console.WriteLine( strTest+ strPath );
     Console.WriteLine( strTest+ "FAiL" );
     Console.Error.WriteLine( strTest + " iCountErrors==" + iCountErrors );
     return false;
     }
   }
开发者ID:ArildF,项目名称:masters,代码行数:48,代码来源:co2900ctor.cs

示例5: Main

    static void Main()
    {
        TimeSpan ts = new TimeSpan();
        Stopwatch stopWatch = new Stopwatch();
        stopWatch.Start();

        uint termValue = 0;
        uint result = 0;
        uint firstTerm = 1;
        uint secondTerm = 1;

        while(termValue < 4000001)
        {
            uint tempSum = firstTerm + secondTerm;
            if(tempSum % 2 == 0)
                result += tempSum;
            firstTerm = secondTerm;
            secondTerm = tempSum;
            termValue = tempSum;
        }

        stopWatch.Stop();
        // Get the elapsed time as a TimeSpan value.
        ts = stopWatch.Elapsed;
        Console.WriteLine(result.ToString());
        Console.WriteLine(ts.ToString());
    }
开发者ID:Donnie7,项目名称:DonT,代码行数:27,代码来源:Problem2.cs

示例6: convert_seconds

 public void convert_seconds(int seconds)
 {
     TimeSpan duration = new TimeSpan(0, 0, 0, seconds);
     string output = null;
     output = duration.ToString(@"hh\:mm\:ss");
     Console.WriteLine(output);
 }
开发者ID:madawe,项目名称:TalentBuddy,代码行数:7,代码来源:Time.cs

示例7: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        ObjectName = screenObject.Property("Object Name").Value;
        OSAEObjectState os = OSAEObjectStateManager.GetObjectStateValue(ObjectName);
        CurrentState = os.Value;

        OffTimer = Convert.ToUInt16(OSAEObjectPropertyManager.GetObjectPropertyValue(ObjectName, "OFF TIMER").Value);
        TimeInState = (int)os.TimeInState;

        string sBackColor = screenObject.Property("Back Color").Value;
        string sForeColor = screenObject.Property("Fore Color").Value;
        string sPrefix = screenObject.Property("Prefix").Value;
        string sSuffix = screenObject.Property("Suffix").Value;
        string iFontSize = screenObject.Property("Font Size").Value;

        if (CurrentState == "OFF")
            sValue = os.StateLabel;
        else
        {
            span = TimeSpan.FromSeconds(OffTimer - TimeInState); //Or TimeSpan.FromSeconds(seconds); (see Jakob C´s answer)
            sValue = span.ToString(@"mm\:ss");
        }

        TimerLabel.Text = sValue;
        TimerLabel.Attributes.Add("Style", "position:absolute;top:" + (Int32.Parse(screenObject.Property("Y").Value) + 50).ToString() + "px;left:" + (Int32.Parse(screenObject.Property("X").Value) + 10).ToString() + "px;z-index:" + (Int32.Parse(screenObject.Property("ZOrder").Value) + 10).ToString() + ";");

        if (sBackColor != "")
        {
            try
            {
                TimerLabel.BackColor = Color.FromName(sBackColor);
            }
            catch (Exception)
            {
            }
        }
        if (sForeColor != "")
        {
            try
            {
                TimerLabel.ForeColor = Color.FromName(sForeColor);
            }
            catch (Exception)
            {
            }
        }
        if (iFontSize != "")
        {
            try
            {
                TimerLabel.Font.Size = new FontUnit(iFontSize);
            }
            catch (Exception)
            {
            }
        }
    }
开发者ID:VeronicaMartin,项目名称:Open-Source-Automation,代码行数:57,代码来源:ctrlTimerLabel.ascx.cs

示例8: CheckTimeSpan

 public void CheckTimeSpan(TimeSpan value, string format)
 {
     var parsed = Format.Parse(format);
     var formatter = new StringFormatter(pool);
     formatter.Append(value, parsed);
     var result = formatter.ToString();
     var clrResult = value.ToString(format, CultureInfo.InvariantCulture);
     Assert.Equal(clrResult, result);
 }
开发者ID:GrimDerp,项目名称:corefxlab,代码行数:9,代码来源:TimeSpanFormattingTests.Generated.cs

示例9: FormatTimeSpan

        public void FormatTimeSpan()
        {
            var time = new TimeSpan(1000, 23, 40, 30, 12345);
            var sb = new StringFormatter();

            sb.Append(time);
            Assert.Equal(time.ToString("", CultureInfo.InvariantCulture), sb.ToString());
            sb.Clear();
        }
开发者ID:jkotas,项目名称:corefxlab,代码行数:9,代码来源:PrimitiveFormattingTests-Time.cs

示例10: runTest

 public Boolean runTest()
   {
   Console.WriteLine( s_strTFPath +" "+ s_strTFName +" ,for "+ s_strComponentBeingTested +"  ,Source ver "+ s_strDtTmVer );
   String strBaseLoc;
   StringBuilder sblMsg = new StringBuilder( 99 );
   m_verbose = false;
   try
     {
     m_strLoc = "Loc_normalTests";
     int D = 3;      
     int h = 4;      
     int m = 5;      
     int s = 42;     
     TimeSpan test = new TimeSpan();
     String   teststr =  "" ;
     test = TimeSpan.MinValue;
     TestValue( test.ToString(  ), test, "r" );
     for ( D = 0; D < 100; D += 10 ) {
     for ( h = 0; h < 24; h+=5 ) {
     for ( m = 0; m < 60; m += 5 ) {
     for ( s = 0; s < 60; s += 15 ) {
     teststr =  D + "." + h +":"+m+":"+s ;
     test = new TimeSpan( D, h, m, s );
     TestValue( teststr, test, "." );
     } 
     }
     }
     }
     m_strLoc = "Loc_exepTests";
     TestException( null, "System.ArgumentNullException", "A" );
     TestException( "00.5555.12.09", "System.OverflowException", "F" );
     TestException( "", "System.FormatException", "F" );
     Console.Write(Environment.NewLine);
     Console.WriteLine( "Total Tests Ran: " + iCountTestcases + " Failed Tests: " + iCountErrors );
     }
   catch( Exception exc_general )
     {
     ++iCountErrors;
     Console.WriteLine( "Error Err_8888yyy ("+ s_strTFAbbrev +")!  Unexpected exception thrown sometime after m_strLoc=="+ m_strLoc +" ,exc_general=="+ exc_general );
     }
   if ( iCountErrors == 0 )
     {
     Console.WriteLine( "paSs.   "+ s_strTFPath +" "+ s_strTFName +"  ,iCountTestcases=="+ iCountTestcases );
     return true;
     }
   else
     {
     Console.WriteLine( "FAiL!   "+ s_strTFPath +" "+ s_strTFName +"  ,iCountErrors=="+ iCountErrors +" ,BugNums?: "+ s_strActiveBugNums );
     return false;
     }
   }
开发者ID:ArildF,项目名称:masters,代码行数:51,代码来源:co6009fromstring.cs

示例11: Update

    // Update is called once per frame
    void Update()
    {
        if (PlayerData.Time != null & PlayerData.Time.Length > 0)
        {
            DateTime time = new DateTime();
            time = DateTime.Parse(PlayerPrefs.GetString("Time"));

            TimeSpan diff = new TimeSpan();

            diff = DateTime.Now - time;

            text.text = diff.ToString();
        }
    }
开发者ID:Lukasz199312,项目名称:SmithCrafter,代码行数:15,代码来源:PDATA.cs

示例12: Update

    void Update()
    {
        TimeSpan timeOne = new TimeSpan();
        TimeSpan timeTwo = new TimeSpan();
        Stopwatch timer = Stopwatch.StartNew();

        FunctionThatDoesStuff();
        timeOne = timer.Elapsed;
        AnotherFunction();
        timeTwo = timer.Elapsed;

        timer.Stop();
        UnityEngine.Debug.Log("Time One: " + timeOne.ToString() + "    Time Two: " + (timeTwo - timeOne).ToString());
    }
开发者ID:devgr,项目名称:NashGameCode,代码行数:14,代码来源:PerformanceTimer.cs

示例13: GetTime

	protected string GetTime(TimeSpan time)
	{
		if (time == TimeSpan.MinValue || time == TimeSpan.MaxValue)
			return "";

		string s = time.ToString();

		if (s.Length > 12)
			s = s.Substring(0, 12);

		if (time.TotalSeconds <= 1)
			s = string.Format("<font color=gray>{0}</font>", s);

		return s;
	}
开发者ID:MajidSafari,项目名称:bltoolkit,代码行数:15,代码来源:Counters.aspx.cs

示例14: timer1_Tick

    protected void timer1_Tick(object sender, EventArgs e)
    {
        string sf = ddl.SelectedValue.ToString() ;
        string tt = TextBox1.Text + " " + sf;

        DateTime d1 = TextBox1.Text != string.Empty ? Convert.ToDateTime(tt) : DateTime.MinValue;

        TimeSpan tspan = d1 - DateTime.Now;
        tspan = new TimeSpan(tspan.Days, tspan.Hours, tspan.Minutes,tspan.Seconds);
        //        remaining.Seconds);
        if (tspan.TotalSeconds < 0)
            tspan = TimeSpan.Zero;

        Label1.Text = tspan.ToString();
    }
开发者ID:vasanibhadresh,项目名称:webstudio-demo,代码行数:15,代码来源:Default2.aspx.cs

示例15: Page_Load

 protected void Page_Load(object sender, EventArgs e)
 {
     DataView dv = (DataView)DateSelect.Select(DataSourceSelectArguments.Empty);
     DateTime dd = (DateTime)dv.Table.Rows[0][0];
     TextBox1.Text = dd.ToShortDateString();
     TextBox2.Text = ((int)dv.Table.Rows[0][1]).ToString();
     era = (Double)dv.Table.Rows[0][2];
     gt = (Double)dv.Table.Rows[0][3];
     tgt.Text = gt.ToString("n2");
     tera.Text = era.ToString("n2");
     DataView dvd = (DataView)EventDetails.Select(DataSourceSelectArguments.Empty);
     dt = (DateTime)dvd.Table.Rows[0][0];
     st = (TimeSpan)dvd.Table.Rows[0][1];
     et = (TimeSpan)dvd.Table.Rows[0][2];
     rdate.Text = dt.ToShortDateString();
     stime.Text = st.ToString();
     etime.Text = et.ToString();
 }
开发者ID:romyromano,项目名称:tanghalangpasigenyo,代码行数:18,代码来源:ConfirmSEvent.aspx.cs


注:本文中的TimeSpan.ToString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。