本文介绍了如何在今天午夜获取 NSDate 对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
获取表示当天午夜的 NSDate 对象的最有效方法是什么?
What is the most efficient way to obtain an NSDate object that represents midnight of the current day?
推荐答案试试这个:
NSDate *const date = NSDate.date; NSCalendar *const calendar = NSCalendar.currentCalendar; NSCalendarUnit const preservedComponents = (NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay); NSDateComponents *const components = [calendar components:preservedComponents fromDate:date]; NSDate *const normalizedDate = [calendar dateFromComponents:components];更多推荐
如何在今天午夜获取 NSDate 对象?
发布评论