I am trying to parse 11/23/2011 23:59:59 UTC +0800 as a c# datetime object but trying the standard datetime parse method or even the datetime exact parse I get invalid date.
Any ideas?
I am trying to parse 11/23/2011 23:59:59 UTC +0800 as a c# datetime object but trying the standard datetime parse method or even the datetime exact parse I get invalid date.
Any ideas?
I would suggest you parse to a
DateTimeOffset
instead of aDateTime
, as recommended in MSDN when using a time zone offset specifier in the format string:You can then convert that to a
DateTime
value in UTC if you want, but there's no such thing as "aDateTime
with an offset of 8 hours" - aDateTime
is either regarded as universal, local or unspecified, with nowhere for a specific offset to be stored.DateTime
is a curious type in various ways, and can cause problems for the unwary developer.Msdn for Format settings: https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx
for extension method:
For test: https://dotnetfiddle.net/xdnjGy
I think you need to use ParseExact http://msdn.microsoft.com/en-us/library/w2sa9yss.aspx
As written by James, you can try
You'll get a date in the "local" time.