Formats given datetime instance according to ISO 8601 specification and returns formatted date as a string. - CSharp System

CSharp examples for System:DateTime Format

Description

Formats given datetime instance according to ISO 8601 specification and returns formatted date as a string.

Demo Code


using System.Globalization;
using System;/*from  w w  w .j a v a 2 s  . c  o  m*/

public class Main{
        /// <summary>
    ///   <para>Formats given date/time instance according to ISO 8601 specification and returns formatted date as a string.</para>
    /// </summary>
    /// <param name="self">Date/time object instance.</param>
    /// <returns>Formatted date/time value as a string.</returns>
    /// <seealso cref="DateTimeFormatInfo"/>
    public static string ISO8601(this DateTime self)
    {
      return self.ToString("o");
    }
}

Related Tutorials