Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Understanding time of day functions
Message
 
 
To
20/12/2018 13:33:54
General information
Forum:
C#
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01664711
Message ID:
01664722
Views:
36
>>Hi,
>>
>>When I use the following function to get the time of the day:
>>
>>tsTime1 = new TimeSpan(24, 0, 0);
>>// tsTime1 is 1:00:00:00.  And I thought it should be 24:00:00
>>
>>
>>When I use the following time of the day:
>>
>>tsTime2 = new TimeSpan(24, 60, 0);
>>// txTime2 is 1:01:00:00
>>
>>
>>How do I get the time of exactly 24:00:00? So that when I compare it with DateTime.Now.TimeOfDay I have the correct result.
>>
>>TIA
>>
>>Update: I found this thread:
>>https://stackoverflow.com/questions/246225/best-way-to-create-a-midnight-datetime-in-c-sharp
>>
>>which shows that midnight time is "00:00:00"
>>
>>What puzzles me is how do you compare is the current time (defined by an hour and minutes, e.g. 24, 00) compares to this time? That is, is now before the midnight or after?
>
>Midnight is beginning of a day, not the end.
>Perhaps you will be better off using datetime?

Maybe. But ...
My code works when I specify the end of the 24-hour day time as 23 hour and 59 minutes. It works.
I thought it would look "better" if I specify the end of the date time as 24 hour and 00 minutes. But to test it I need to set some variable (in my C# code) to the exactly midnight time. And I don't know how to do it.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform