Reputation: 329
Proxy code reads DATETIME("2016-05-08T12:33:11.991-05:00") from XML, and then creates DateTime object. Then my code reads the DateTime. I would like to get the TIME as it was in XML file but without TZ ("2016-05-08 12:33:11.991000"). How do I get that?
(Note that I do not have access to the code used for creating DateTime object from XML file. DateTime.Kind says LOCAL.)
psuedocode
Input-XML "2016-05-08T12:33:11.991-05:00". //Creates DateTime object called DtXML.
.....
I do not have access to this code.
.....
DtXML.ToString("yyyy-MM-dd HH:mm:ss.ffffff"); //This gives 2016-05-08 10:33:11.991000
DtXML.Kind;// This is LOCAL.
I want to get "2016-05-08 12:33:11.991000".
Is this possible?
Upvotes: 1
Views: 47
Reputation: 783
Have you tried this?
var expectedDT = DateTime.SpecifyKind(DtXML.ToUniversalTime(), DateTimeKind.Local);
Upvotes: 0
Reputation: 16956
You could use DateTimeOffset
and do this.
string s = "2016-05-08T12:33:11.991-05:00";
var dtOffset =DateTimeOffset.Parse(s, null);
DateTime dt = dtOffset.DateTime; // 08.05.2016 12:33:11
Console.WriteLine(dtOffset.DateTime.ToString("yyyy-MM-dd HH:mm:ss.ffffff")); // prints - 2016-05-08 12:33:11.991000
Check this code
Upvotes: 1