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