emelia emelia - 11 months ago 64
C# Question

C#: Parse Datetime.Now to specific fromat

I want to parse

into formatted string like


Answer Source

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)