Saturday, September 25, 2010

How to calculate hour difference

Example:05:00 15:00 = 10 hours07:00 12:00 = 5 hours
Code:
int y = DateTime.Now.Year, m = DateTime.Now.Month, d = DateTime.Now.Day, s = 0;
DateTime startTime = new DateTime(y, m, d, 5, 30, s); // 05:40 Hour
DateTime endTime = new DateTime(y, m, d, 17, 45, s); // 17:45 Hour
TimeSpan diff = endTime - startTime;
int hourDiff = diff.Hours; // 12 Hours
int minDiff = diff.Minutes; // 15 Mins
double totDiffHours = (double)hourDiff + (double)minDiff / 60; // 12.25 Hours

No comments:

iPhone Launch Screen Sizes

iPhone Portrait iOS 8 Retina HT 5.5 = 1242 X 2208 Retna HD 4.7 = 750 X 1134 iPhone Landscape iOS 8 Retina HD 5.5  2208 X 1242 iPho...