how to convert this DateTime.Now to something like this 2018-04-07T00:00:00Z
I tried to do something like this
string date = Newtonsoft.Json.JsonConvert.SerializeObject(DateTime.Now);
how to convert this DateTime.Now to something like this 2018-04-07T00:00:00Z
I tried to do something like this
string date = Newtonsoft.Json.JsonConvert.SerializeObject(DateTime.Now);
You can use DateTime.Now.ToString("u").
Please read below post for more information:
https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings
You can do something like this:
string date = DateTime.Now.ToUniversalTime()
.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'");
I suspect the answer you need is by using
string date = DateTime.Now.ToString("O");
This is called the RoundTrip kind because it is designed to preserve information through a serialization/deserialization round trip, which sounds like it might be what you're doing. And it includes the T in the middle as requested.