Initialize a time span to zero : TimeSpan « Development Class « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Development Class » TimeSpanScreenshots 
Initialize a time span to zero
 

using System;

public class ToString
{
   public static void Main()
   {
      TimeSpan span;

      // Initialize a time span to zero.
      span = TimeSpan.Zero;
      Console.WriteLine(FormatTimeSpan(span, true));

   }

   private static string FormatTimeSpan(TimeSpan span, bool showSign)
   {
      string sign = String.Empty;
      if (showSign && (span > TimeSpan.Zero)) 
         sign = "+";  

      return sign + span.Days.ToString("00""." 
             span.Hours.ToString("00"":" 
             span.Minutes.ToString("00"":" 
             span.Seconds.ToString("00""." 
             span.Milliseconds.ToString("000");
   }
}

   
  
Related examples in the same category
1.new TimeSpan(2, 12, 0, 0)
2.TimeSpan.TicksPerDay
3.Initialize a time span to 14 days
4.Initialize a time span to 1:02:03
5.Initialize a time span to 250 milliseconds
6.Initalize a time span to 99 days, 23 hours, 59 minutes, and 59.9999999 seconds
7.Calculation based on the TimeSpanCalculation based on the TimeSpan
8.Subtract 15 minutes from the current TimeSpan and print the result
9.Measuring the Time Taken to Add Some Numbers
10.Use FromDays(), FromHours(), FromMinutes(), FromSeconds(), FromMilliseconds(), and FromTicks() methods to create new TimeSpan instances
11.Use the Parse() method to convert strings to TimeSpan instances
12.Use the Add() method to add a TimeSpan instance to another
13.Use the Subtract() method to subtract a TimeSpan instance from another
14.Use the Duration() method to add two TimeSpan instances
15.Use the Negate() method to add two TimeSpan instances
16.Use the Parse() method to convert strings to TimeSpan instances
17.Create a TimeSpan instance, specifying the hours, minutes, and seconds
18.Create a TimeSpan instance, specifying the days, hours, minutes, and seconds
19.Create a TimeSpan instance, specifying the days, hours, minutes, seconds, and milliseconds
20.Create a TimeSpan instance, specifying the number of ticks
21.Display the properties for myTimeSpan
22.Initalize a timespan to 25 milliseconds
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.