您可能希望從原來的日期提取顯著日期組件
NSDate *date = [NSDate date];
NSCalendar *gregorianCalendar = [NSCalendar calendarWithIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *componentsDate = [gregorianCalendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:date];
然後,與他們建立新的約會
NSDateComponents *toDateComponents = [NSDateComponents new];
[toDateComponents setYear:[componentsDate year]];
[toDateComponents setMonth:[componentsDate month]];
[toDateComponents setDay:[componentsDate day]];
[toDateComponents setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
NSDate *toDate = [gregorianCalendar dateFromComponents:toDateComponents];
最後,得到時間間隔
NSTimeInterval toDateTimeInterval = [toDate timeIntervalSince1970];
你所說的「無時,分,秒」是什麼意思?你的意思是指在當天所有時間都是折扣的秒數?所以基本上直到剛剛過去的午夜? –