Update date of datetime object when using datetime.addhours (-1)
I have a datetime object that I want to remove one hour to display the corect time in a different timezone. I am using datetime.addhours (-1) where -1 is the config value. This works most of the time, except when I set the time to 12:59 pm today, it displays 11:59 am today. When it should display 11:59 pm. Is it possible for addDays () to consider a date?
I noticed that you didn't mention which version of the framework you are using. If you are using 2.0 SP1, 3.0 SP1, or 3.5 SP1, you can use the DateTimeOffset structure . Then you just specified the timezone offset and everything should work.
Hope it helps!
source to share
Generally speaking, if you are handling timezone problems, you should use functions that store the datetime in UTC and then display the correct TZ.
However, if this is overkill for your application, what you do is correlation.
DateTime datetime = new DateTime( 2008,12,17,0,59, 0 ); datetime = datetime.AddHours(-1);
This results in 23:59:00 or 11:59 PM on 12/16/2008.
The times you feed may not have a proper am / pm indication.
source to share