I am using saber soap API for flight Booking.
I have an DateTime
object which requires a parameter with the timezone. The input should be like "2016-03-01T10:00:00-06:00"
At the moment I am getting the value like
DateTime dt = DateTime.UtcNow;
string date = dt.ToString();
string tstamp = dt.ToString("mm-dd-yyyyTHH:mm:sszzz");
DateTimeOffset tstamp = DateTimeOffset.Parse(date);
DateTime datetime = tstamp.DateTime;
but when I convert it back to DateTime
the timezone gets removed automatically. I cannot convert the object to DateTimeoffset
because the API requires it in the DateTime
format.
I think this could help you, it is possible to get the dateTime you desire or to get the offset as TimeSpan and then add it to your datetime if needed or save it.
Edit: now I see you maybe just need to get the string from a DateTimeOffset object, not from a DateTime object.
DateTime dt = DateTime.UtcNow;
string date = dt.ToString();
string tstampString = dt.ToString("MM-dd-yyyyTHH:mm:ssZZZ");
DateTimeOffset tstampDT = DateTimeOffset.Parse(date);
DateTime datetimeCurrent = tstampDT.DateTime;
DateTime datetimeUTC = tstampDT.UtcDateTime;
DateTime datetimeLocal = tstampDT.LocalDateTime;
TimeSpan offsetFromUTC = tstampDT.Offset;
edit:
string tstampOffsetString = tstampDT.ToString("MM-dd-yyyyTHH:mm:sszzz");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With