I want to convert a DateTime? to string. If a date is null then return "", else return a string format like this: "2020-03-05T07:52:59.665Z". The code is something like this but it won't work. It said "DateTime?" do not contain a definition for "ToUniversalTime". Someone know how to fix this?
DateTime? date = DateTime.UtcNow;
var dateInUTCString = date == null ? "" : date.ToUniversalTime().ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'");