iOS time processing time comparison by Nicky.tsui

Source: Internet
Author: User

With the project requirements, the server returns a

Order_canceled_time Order Automatic Cancellation time

If I want to make a comparison with the current time and then generate a countdown time

Well, first of all, we need to know

Order_canceled_time the time format returned by this field

" Order_canceled_time " " 2015-08-20 13:50:40 ";

Take this time as an example, the format is "year-month-day-minute-second"

Convert the time in this format to nsdate with NSDateFormatter

Specific code:

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];        [Formatter Setdatestyle:nsdateformattermediumstyle];        [Formatter Settimestyle:nsdateformattershortstyle];        [Formatter Setdateformat: @" YYYY-MM-DD HH:mm:ss " ];         *tranfromdate = [Formatter datefromstring:@ "2015-08-20 13:50:40"];

Then compare the time with NSDate to get the difference

NSDate *currentdate == [Tranfromdate timeintervalsincedate:currentdate];

At this point, TimeInterval is the number of seconds of two time difference.

And then convert the number of seconds into hours-minutes-seconds.

        LongHours =0; Longminutes =0; Longseconds =0; Hours= (Long) timeinterval/3600; Minutes= (Long) timeinterval%3600/ -; Seconds= (Long) timeinterval% -; NSLog (@"%ld%ld seconds payment for order remaining%ld", hours,minutes,seconds);

iOS time processing time comparison by Nicky.tsui

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.