I am trying to explain a few things:
I have a DateTime object that requires a timezone parameter.
No, you do not.
A DateTime has no implicit format. It just has a date and time value. The concept of "Format" is applied only when you get a textual representation (aka string ). That way you might have a string with an offset part, but not a DateTime.
but when I put it back in DateTime, the timezone is deleted automatically ..
And DateTime itself does not contain real-time information. He may know if it is UTC or Local , but not what local actually means. Also DateTimeOffset has no time zone information. It just has DateTime and UTC Offset . But this data is not enough to determine the time zone, since different time intervals can have the same offset.
But if you really want to generate the input "2016-03-01T10:00:00-06:00" , I can provide two ways, I donβt even suggest
A Genereate-related DateTime instance based on this value sets the time zone of your system, which is 6 hours behind as part offfset (since using the zzz format specifier is not recommended for DateTime, which is not related to the Kind property) and formats your DateTime as;
DateTime dt = new DateTime(2016, 3, 1, 10, 0, 0); Console.WriteLine(dt.ToString("yyyy-MM-ddTHH:mm:sszzz"));
Create an instance of DateTimeOffset based on this DateTime and the offset part, after you format it as:
var dto = new DateTimeOffset(dt, TimeSpan.FromHours(-6)); Console.WriteLine(dto.ToString("yyyy-MM-ddTHH:mm:sszzz"));