To Standard Date Time String - CSharp System

CSharp examples for System:DateTime Format

Description

To Standard Date Time String

Demo Code

// Copyright (c) Microsoft Corporation. All rights reserved. 
using System;/* w w w  . j a v  a 2s . co m*/

public class Main{
        public static string ToStandardDateTimeString(this DateTime dateTime)
        {
            return dateTime.Kind == DateTimeKind.Utc
                       ? dateTime.ToString("yyyy-MM-ddTHH:mm:ssZ")
                       : dateTime.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ"); // ISO 8601
        }
}

Related Tutorials