I have a minor issue in handling DateTime in C#. I have designed a windows application that interacts with Harris automation system. The application receives all triggers for EPG programs. Now I have this issue:
trigger received
DateTime: 2012-01-31 23:58:23trigger exact time :
00:03:53( this value can be either > now() or < now()
Here is the code that handles this:
DateTime segmentStartDateTime = DateTime.Now.ToUniversalTime().Date;
segmentStartDateTime = segmentStartDateTime + item.TIME;
If we test this code with the case above, I get segmentStartDateTime = 2012-01-31 00:03:53, which is the wrong value (the right value should be 2012-02-01 00:03:53).
I am sure one of you have faced this issue before and I’ll appreciate any help to fix this (to determine either the time is in the current day or in the day after).
A few more examples:
1)
Input : – Current Time : 2012-03-08 13:27:00 – Received TimeSpan as string : 13:28:30
Output – The program will start at: 2012-03-08 13:28:30
2)
Input : – Current Time : 2012-03-08 23:58:19 – Received TimeSpan as string : 00:02:15
Output – The program will start at: 2012-03-09 00:02:15 (day after)
3)
Input : – Current Time : 2012-03-08 23:58:19 – Received TimeSpan as string : 23:57:43
Output – The program will start at: Now, it’s already time (2012-03-08 23:57:43)
Not sure how this interacts with DST. But IMO
DateTimeshouldn’t be used for local times anyways.Just tested, and both your examples work with my code: