iOS time processing

Source: Internet
Author: User

Time remaining processing
Current Time 2014-08-27 09:06
NSDate *now = [NSDate Date];
Expiry date 2014-08-28 00:00
NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
Fmt.dateformat = @ "YYYY-MM-DD";
NSDate *deadtime = [FMT dateFromString:self.deal.purchase_deadline] datebyaddingtimeinterval:24 * 3600];
Compare 2 time gaps
Nscalendar *calendar = [Nscalendar Currentcalendar];
Nscalendarunit unit = Nscalendarunitday | Nscalendarunithour | Nscalendarunitminute;
nsdatecomponents *cmps = [Calendar components:unit fromdate:now todate:deadtime options:0];
if (Cmps.day > 365) {
Self.leftTimeButton.title = @ "does not expire within one year";
} else {
Self.leftTimeButton.title = [NSString stringwithformat:@%d days%d hours%d minutes, cmps.day, Cmps.hour, Cmps.minute];
}

iOS time processing

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.