Standard TimeSpan format: G (2) : TimeSpan Format « Date Time « C# / C Sharp






Standard TimeSpan format: G (2)

   


using System;
using System.Globalization;

public class Example
{
   public static void Main()
   {
      TimeSpan interval1, interval2;
      interval1 = new TimeSpan(7, 45, 16);
      interval2 = new TimeSpan(18, 12, 38);

      Console.WriteLine("{0:G} ", interval1);
      Console.WriteLine(String.Format(new CultureInfo("fr-FR"), "{0:G} ", interval1));

      interval1 = new TimeSpan(0, 0, 1, 14, 36);
      interval2 = TimeSpan.FromTicks(2143756);      
      Console.WriteLine("{0:G}", interval1);
   }
}
//0:07:45:16.0000000 
//0:07:45:16,0000000 
//0:00:01:14.0360000

   
    
    
  








Related examples in the same category

1.TimeSpan format: %d
2.TimeSpan format: d\.hh\:mm\:ss
3.TimeSpan format: d\.hh\:mm\:ss for new TimeSpan(3, 4, 3, 17)
4.TimeSpan format: h(hour) and m(minutes)
5.Indicate format for TimeSpan parse
6.Standard TimeSpan Format String: c
7.Standard TimeSpan format: g
8.Converts TimeSpan to string with ToString() using the specified format: "c", "g", "G"
9.Converts TimeSpan to string using the specified format and culture-specific formatting information.
10.Converts TimeSpan to string with default ToString
11.TimeSpan Format with Flag
12.Convert To TimeSpan