[Code Note] iOS-computing time difference, note ios-Time Difference

Source: Internet
Author: User

[Code Note] iOS-computing time difference, note ios-Time Difference

I. Code.

-(Void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. // time format: 18:34:31 NSLog (@ "% ld", [self getTimeInterval: @ "00:00:00"]);} // calculate the time difference-(NSInteger) getTimeInterval :( NSString *) sendDateString {NSInteger minute; if (sendDateString = nil | sendDateString. length = 0) {;} else {NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat: @ "yyyy-MM-dd HH: mm: ss "]; // current time NSDate * currentdate = [NSDate date]; NSDate * currentDate = [dateFormatter dateFromString: [dateFormatter stringFromDate: currentdate]; NSLog (@ "--- currentdate -- % @", currentDate); // End Time NSDate * endDate = [dateFormatter dateFromString: sendDateString]; NSLog (@ "--- endDate -- % @", endDate); // get the time difference NSTimeInterval time = [currentDate timeIntervalSinceDate: endDate]; NSLog (@ "--- time --- % ld", (long) time ); NSLog (@ "-- minitus -- % ld", (long) time); NSLog (@ "--- days -- % d", (int) time) /(3600*24); NSLog (@ "--- hours -- % d", (int) time) % (3600*24)/3600);} return minute ;}

 

2. output.

10:14:12. 467 calculation time difference [1519: 59582] --- currentdate -- 02:14:12 + 00002015-10-23 10:14:12. 467 calculation time difference [1519: 59582] --- endDate -- 16:00:00 + 00002015-10-23 10:14:12. 467 calculation time difference [1519: 59582] --- time --- 82448522015-10-23 10:14:12. 467 calculation time difference [1519: 59582] -- minitus -- 82448522015-10-23 10:14:12. 467 calculation time difference [1519: 59582] --- days -- 952015-10-23 10:14:12. 468 calculation time difference [1519: 59582] --- hours -- 102015-10-23 10:14:12. 468 calculation time difference [1519: 59582] 0

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.