Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to define Time type?
Message
De
01/12/2007 21:42:46
 
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 2.0
Divers
Thread ID:
01272620
Message ID:
01272670
Vues:
14
I forgot about Timespan. It is easier following Cetins suggestion as

DateTime.Now.TimeOfDay

returns a Timespan object. If you're doing this in a loop and worried about performance, you'll have to test to see what kind of performance hit, if any, to create a Timespan object out of a Datetime.

>>>I need to do a comparison of Time of day to a Time variable.
>>>
>>>I would use code like this:
>>>
>>>
>>>if (DateTime.Now.CompareTo( MyTime ) >= 0)
>>>
>>>
>>>My question is, say I want to set value of "12:40" to the variable Mytime. How do I define it?
>>>
>>>I tried:
>>>
>>>
>>>DateTime.Now.TimeOfDay MyTime = "12:40";
>>>
>>>
>>>But I get compiler error.
>>>
>>>Thank you in advance for your help.
>>
>>
>>TimeSpan MyTime = new TimeSpan(12,40,0);
>>if ( DateTime.Now.TimeOfDay.CompareTo(MyTime) >= 0 )
>>
Cetin
>
>Thank you for your help. I didn't know you can use TimeSpan type with assigning only hours, minutes, seconds. Examples of TimeSpan I saw always set it to a difference between two datetime values. But your example definetely works. I will have to decide whether to use TimeSpan or DateTime, as Perry suggested. My guess is that TimeSpan should be faster as it stores only the hours whereas DateTime has a longer value.

(On an infant's shirt): Already smarter than Bush
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform