Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi all,

 

I'm trying to compare 2 DateTimes in C# to see if a specific time difference (5 seconds) has elapsed. I've been told that the best/most efficient way to compare them is to use a TimeSpan object in the code because it takes into account timing over midnight/new year/etc. However, I cannot see how to go about this.

 

Any help would be much appreciated.

  • Leaders
Posted
If you use the .Subtract method of a DateTime, it returns a timespan which represents the 'TimeSpan' between the two dates... you can check the .TotalSeconds of the timespan to see if it is more than 5 seconds. :)

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Posted

Thats great thanks :)

 

I found a way similar to yours by creating the above TimeSpan and also creating another TimeSpan of 5 seconds and then comparing them. I prefer your method though.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...