查找两个NSDates之间的时间差异Swift [duplicate]

时间:2021-01-09 21:33:43

This question already has an answer here:

这个问题已经有了答案:

I have two NSDate objects: startDate and endDate, both are NSDate objects. I want to find the difference between these two dates. I know there is a resolved question about this already (Getting the difference between two NSDates in (months/days/hours/minutes/seconds)), but I want to know if there is a quicker way to do this (less execution code). Is that possible?

我有两个NSDate对象:startDate和endDate,它们都是NSDate对象。我想找出这两次约会的不同之处。我知道有一个问题已经解决了(在两个nsdate(月/天/小时/分/秒)之间),但是我想知道是否有更快的方法来完成这个(更少的执行代码)。这有可能吗?

1 个解决方案

#1


40  

Yes if you look at the second answer to your linked question you can do this: let interval = laterDate.timeIntervalSinceDate(earlierDate)

是的,如果你看第二个问题的答案你可以这样做:让interval = later . timeintervalsincedate (earlierDate)

#1


40  

Yes if you look at the second answer to your linked question you can do this: let interval = laterDate.timeIntervalSinceDate(earlierDate)

是的,如果你看第二个问题的答案你可以这样做:让interval = later . timeintervalsincedate (earlierDate)