C# DateTimeOffset ToString(IFormatProvider)

Description

DateTimeOffset ToString(IFormatProvider) converts the value of the current DateTimeOffset object to its equivalent string representation using the specified culture-specific formatting information.

Syntax

DateTimeOffset.ToString(IFormatProvider) has the following syntax.


public string ToString(
  IFormatProvider formatProvider
)

Parameters

DateTimeOffset.ToString(IFormatProvider) has the following parameters.

  • formatProvider - An object that supplies culture-specific formatting information.

Returns

DateTimeOffset.ToString(IFormatProvider) method returns A string representation of the value of the current DateTimeOffset object, as specified by formatProvider.

Example

The following example displays a DateTimeOffset object using CultureInfo objects that represent the invariant culture, as well as four other cultures.


/*from  w w w  . jav  a  2 s  .  c o m*/
using System;
using System.Globalization;
public class MainClass{
  public static void Main(String[] argv){  
    CultureInfo[] cultures = new CultureInfo[] {CultureInfo.InvariantCulture, 
                                               new CultureInfo("en-us"), 
                                               new CultureInfo("fr-fr"), 
                                               new CultureInfo("de-DE"), 
                                               new CultureInfo("es-ES")};
    
    DateTimeOffset thisDate = new DateTimeOffset(2014, 5, 1, 9, 0, 0, 
                                                 TimeSpan.Zero);                                            
    
    foreach (CultureInfo culture in cultures)
    {
       string cultureName; 
       if (string.IsNullOrEmpty(culture.Name))
          cultureName = culture.NativeName;
       else
          cultureName = culture.Name;
    
       Console.WriteLine("In {0}, {1}", 
                         cultureName, thisDate.ToString(culture));
    }  
  }
}
    
                                          

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version