I think your format is little bit different than ISO 8601 format.
First of all, when you use any z
format specifier, you always get +
or -
sign depends on your UTC Offset value is negative or positive.
Would be better to get your current local time zone utc offset, format it with hh\\:mm
format and combine your formatted UtcNow
value like;
var utcOffset = TimeZoneInfo.Local.GetUtcOffset(DateTime.UtcNow);
var formattedOffset = utcOffset.ToString("hh\\:mm");
Console.WriteLine(DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss'-'" + formattedOffset));
Or you can use The "s"
standard format specifier and format your offset part with -
string literal as;
Console.WriteLine(DateTime.UtcNow.ToString("s") + utcOffset.ToString("'-'hh\\:mm"));