emelia emelia - 3 months ago 8
C# Question

C#: Parse Datetime.Now to specific fromat

I want to parse

Datetime.Now
into formatted string like


"2016-09-01T02:00:12.7011585Z"

Answer

You can't parse DateTime.Now. It already returns a DateTime, not a string.

You can generate it's string string representation using yyyy-MM-dd'T'HH:mm:ss.fffffff'Z' format with a proper culture like InvariantCulture;

DateTime.Now.ToString("yyyy-MM-dd'T'HH:mm:ss.fffffff'Z'", CultureInfo.InvariantCulture)
Comments