rcaine Posted March 17, 2006 Posted March 17, 2006 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. Quote
Leaders Iceplug Posted March 17, 2006 Leaders Posted March 17, 2006 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. :) Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
rcaine Posted March 17, 2006 Author Posted March 17, 2006 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.