Converts string to DateTimeOffset using the specified formats, culture-specific format information, and style. : DateTimeOffset Format « Date Time « C# / C Sharp






Converts string to DateTimeOffset using the specified formats, culture-specific format information, and style.

Converts string to DateTimeOffset using the specified formats, culture-specific format information, and style.
  

using System;
using System.Globalization;
public class Test
{
   public static void Main()
   {  
        string[] formats = new string[] {@"M/dd/yyyy HH:m zzz", @"MM/dd/yyyy HH:m zzz", 
                                         @"M/d/yyyy HH:m zzz", @"MM/d/yyyy HH:m zzz", 
                                         @"M/dd/yy HH:m zzz", @"MM/dd/yy HH:m zzz", 
                                         @"M/d/yy HH:m zzz", @"MM/d/yy HH:m zzz",                             
                                         @"M/dd/yyyy H:m zzz", @"MM/dd/yyyy H:m zzz", 
                                         @"M/d/yyyy H:m zzz", @"MM/d/yyyy H:m zzz", 
                                         @"M/dd/yy H:m zzz", @"MM/dd/yy H:m zzz", 
                                         @"M/d/yy H:m zzz", @"MM/d/yy H:m zzz",                               
                                         @"M/dd/yyyy HH:mm zzz", @"MM/dd/yyyy HH:mm zzz", 
                                         @"M/d/yyyy HH:mm zzz", @"MM/d/yyyy HH:mm zzz", 
                                         @"M/dd/yy HH:mm zzz", @"MM/dd/yy HH:mm zzz", 
                                         @"M/d/yy HH:mm zzz", @"MM/d/yy HH:mm zzz",                                 
                                         @"M/dd/yyyy H:mm zzz", @"MM/dd/yyyy H:mm zzz", 
                                         @"M/d/yyyy H:mm zzz", @"MM/d/yyyy H:mm zzz", 
                                         @"M/dd/yy H:mm zzz", @"MM/dd/yy H:mm zzz", 
                                         @"M/d/yy H:mm zzz", @"MM/d/yy H:mm zzz"};
        IFormatProvider provider = CultureInfo.InvariantCulture.DateTimeFormat;
        DateTimeOffset result = new DateTimeOffset();
        
           string input = "12/12/1212";
           try
           {
              result = DateTimeOffset.ParseExact(input, formats, provider, DateTimeStyles.AllowWhiteSpaces);
           }
           catch (FormatException)
           {
              Console.WriteLine("Unable to parse {0}.", input);      
           }
    }
}

   
    
  








Related examples in the same category

1.DateTimeOffset format: D (2)DateTimeOffset format: D (2)
2.DateTimeOffset format: dDateTimeOffset format: d
3.DateTimeOffset format: Y or yDateTimeOffset format: Y or y
4.DateTimeOffset custom format specifier: dd MMM yyyyDateTimeOffset custom format specifier: dd MMM yyyy
5.DateTimeOffset format: ddDateTimeOffset format: dd
6.DateTimeOffset format: ddddDateTimeOffset format: dddd
7.DateTimeOffset format: dddd and CultureInfo("fr-fr")DateTimeOffset format: dddd and CultureInfo(
8.DateTimeOffset format: mDateTimeOffset format: m
9.DateTimeOffset format: mm (2)DateTimeOffset format: mm (2)
10.DateTimeOffset format: M (3)DateTimeOffset format: M (3)
11.DateTimeOffset format: MMDateTimeOffset format: MM
12.DateTimeOffset format: t
13.DateTimeOffset format: T (2)
14.DateTimeOffset format: f
15.DateTimeOffset format: F (2)
16.DateTimeOffset format: g
17.DateTimeOffset format: G (2)
18.DateTimeOffset format: R
19.DateTimeOffset format: s
20.DateTimeOffset format: u
21.DateTimeOffset format: Y
22.DateTimeOffset format: y (2)
23.DateTimeOffset format: yy
24.DateTimeOffset format: yyyy
25.Converts string to DateTimeOffset using the specified format and culture-specific format information.Converts string to DateTimeOffset using the specified format and culture-specific format information.
26.Converts string to DateTimeOffset using the specified format, culture-specific format information, and style.Converts string to DateTimeOffset using the specified format, culture-specific format information, and style.
27.Converts DateTimeOffset to string using the specified culture-specific formatting information.
28.Convert DateTimeOffset to string with different culture information
29.Converts DateTimeOffset to string using the specified format.
30.Converts DateTimeOffset to string using the specified format and culture-specific format information.
31.DateTimeOffset format: MMM d, yyyyDateTimeOffset format: MMM d, yyyy
32.Output date using each standard date/time format specifier
33.Output date and time using custom format specification