To Formatted Utc Time - CSharp System

CSharp examples for System:DateTime UTC

Description

To Formatted Utc Time

Demo Code


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

public class Main{
        public static string ToFormattedUtcTime(this DateTime dateTimeValue)
    {
        var formattedUtc = dateTimeValue.ToUniversalTime().ToString("s");
        if (!formattedUtc.EndsWith("Z"))
        {
            formattedUtc += "Z";
        }
        return formattedUtc;
    }
}

Related Tutorials