Find exact difference between two dates

前端 未结 4 869
臣服心动
臣服心动 2021-01-22 19:48

I want some changes in the date comparison.

In my application I am comparing two dates and getting difference as number of Days, but if there is only one day difference

4条回答
  •  Happy的楠姐
    2021-01-22 20:09

    i think this is not correct make the time 00:00:00.

    may be you get difference is less than 24 hour thats why it rounded off and you 0 day.

    Alexander solution is right so use that solution like -

    this works fine for me also.

    NSDate *endDate=[dateFormat dateFromString:now];
            NSTimeInterval interval = [CeremonyDate timeIntervalSinceDate:endDate];
            int diff=interval/86400;//for converting seconds into days.
    

    same problem of rounding a figure you get here but you can sort out that in an understable way.

提交回复
热议问题