How long is two days apart?

Source: Internet
Author: User

NSDate *now = [NSDate Date];

NSDateFormatter *fmt = [[NSDateFormatter alloc] init];

@ "Yyyy-mm-dd HH:mm:ss EEE Z" date and time zone difference Mon +0800

@ "yyyy mm month DD day hh" mm min ss sec "

Fmt.dateformat = @ "Yyyy-mm-dd HH:mm:ss";

NSString *nowstring = [FMT Stringfromdate:now];

NSLog (@ "%@", nowstring);

The format of the #warning string must be the same as the DateFormat format

@ "October 15, 2015 12:20 32 seconds"

NSString *s = @ "2013-1-15 12:20:32";

NSDate *lastdate = [FMT datefromstring:s];

NSLog (@ "%@", lastdate);

NSString *lasts = [FMT stringfromdate:lastdate];

NSLog (@ "%@", lasts);

Nscalendar *calendar = [Nscalendar Currentcalendar];

Nscalendarunit unit = Nscalendarunityear | Nscalendarunitmonth | Nscalendarunitday | Nscalendarunithour | Nscalendarunitminute | Nscalendarunitsecond;

Time difference Component

nsdatecomponents *components = [Calendar components:unit fromdate:lastdate todate:now options: Nscalendarwrapcomponents];

NSLog (@ "%ld%ld", Components.year, Components.month);

NSString *timespace;

if (Components.year > 0) {

Timespace = [NSString stringwithformat:@ "%ld%ld months%ld days ago", Components.year, Components.month, Components.day];

} else {

if (Components.month > 0) {

Timespace = [NSString stringwithformat:@ "%ld months ago", Components.month];

} else {

if (Components.day > 0) {

Timespace = [NSString stringwithformat:@ "%ld days Ago", Components.day];

}

}

}

NSLog (@ "%@", timespace);

How long is two days apart?

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.