Convert To TimeSpan : TimeSpan Format « Date Time « 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.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# / C Sharp » Date Time » TimeSpan FormatScreenshots 
Convert To TimeSpan
      

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace DateTimeUtils {
  public static class Conversion {

    public static TimeSpan ConvertToTimeSpanstring time ) {
      TimeSpan result = TimeSpan.Zero;
      if string.IsNullOrEmptytime ) ) throw new ArgumentNullException"No time given." );

      Regex regex = new Regex"^([0-1][0-9]|[2][0-3]):([0-5][0-9])$" );
      if !regex.IsMatchtime ) ) throw new FormatException"Invalid time format" );

      TimeSpan.TryParsetime, out result );      

      return result;
    }

  }
}

   
    
    
    
    
    
  
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.Standard TimeSpan format: G (2)
9.Converts TimeSpan to string with ToString() using the specified format: "c", "g", "G"
10.Converts TimeSpan to string using the specified format and culture-specific formatting information.
11.Converts TimeSpan to string with default ToString
12.TimeSpan Format with Flag
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.