I want to format a DateTime
to the following format yyyy-MM-ddTHH:mm:ssZ
but keeping it in DateTime
.
This is what I tried:
string t = Convert.ToString(DateTime.UtcNow);
DateTime d2 = DateTime.ParseExact(t, "yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture);
But I am getting the following error :
System.FormatException: 'The string was not recognized as a valid DateTime value.'
this is the result where I want to get: 2018-09-05T09:29:56Z
How can I solve this problem?