c# - Parse string to DateTime, sometimes adds 1 hour (timezone) -


i'm having problem when need parse string datetime. adds hour, doesn't. there reason why does, because don't wan't add hour.

the first example need.

string s = "2016-01-28t20:59:00.000+01:00";             datetime ds = datetime.parse(s); //gives: 28/01/2016 20:59:00 

the second example adds hour, wonder why.

string ss = "2016-05-27t10:38:00.000+01:00"; datetime dss = datetime.parse(ss); //gives: 27/05/2016 11:38:00 

i strongly suspect happens because of daylight saving time of current timezone.

looks timezone has utc +01:00 in january has utc +02:00 in may. that's why second example adds 1 more hour since has 01:00 hour in it's offset part.

but instead of datetime-since string has utc offset-i parse datetimeoffset.

datetimeoffset ds = datetimeoffset.parse(s); 

now have {28.01.2016 20:59:00 +01:00} , {27.05.2016 10:38:00 +01:00} datetimeoffset values saved in theirs .datetime , .offset properties.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -