更新时间:2022-12-09 12:25:17
NSDateFormatter
将日期字符串转换为 NSDate
对象。 - [NSDate timeIntervalSinceDate:]
以秒为单位获取两个日期之间的差异。NSDateFormatter
to convert the date strings into NSDate
objects.-[NSDate timeIntervalSinceDate:]
to get the difference between the two dates in seconds.或者,您可以使用 NSCalendar
和 NSDateComponents
使用组件计算不同日历的分钟差异:fromDate:toDate:options :
方法。
Alternatively, you can use NSCalendar
and NSDateComponents
to calculate the difference in minutes for different calendars by using the components:fromDate:toDate:options:
method.