查找两个 NSDates Swift 之间的时间差 [英] Finding the difference in time between two NSDates Swift
问题描述
我有两个 NSDate 对象:startDate 和 endDate,都是 NSDate 对象.我想找到这两个日期之间的差异.我知道已经有一个已解决的问题(获取两个 NSDates 之间的差异(月/天/小时/分钟/秒)),但我想知道是否有更快的方法来做到这一点(更少的执行代码).这可能吗?
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?
推荐答案
是的,如果您查看链接问题的第二个答案,您可以这样做:let interval = laterDate.timeIntervalSinceDate(earlierDate)
Yes if you look at the second answer to your linked question you can do this:
let interval = laterDate.timeIntervalSinceDate(earlierDate)
这篇关于查找两个 NSDates Swift 之间的时间差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!