Previously I was facing this issue and solved as described in the post.
Currently after DayLight Saving implementation I observed the issue that if I am selecting
DateTime startDate=new DateTime(2012,1,20); //Eastern Timezone (UTC -5:00)
after serializing it would convert it to:
string serializeDate= serializer.Serialize(startDate); //In ticks 20-Jan 2012 05:00AM
on deserializing and ToLocalTime()
DateTime afterDeserialize= serializer.Deserialize<DateTime>(serializeDate);
afterDeserialize.ToLocalTime();
It was working perfect until:
I unchecked the Automatically adjust clock for Daylight Saving Time
.
Now its on serialization add 4:00 hours
(due to Daylight Saving Time) but on ToLocalTime()
subtracting -5:00 hours
due to environment daylight saving time which change the date of my object subtracting one day.
How I can inject the current environment Daylight Saving time on both conversion?