Objective-C 开发:日期、时间、定时器与异步处理技术详解
1. 日期与时间处理
在开发中,日期和时间的处理是常见需求。下面通过一个示例展示如何进行日期计算。
#import <Foundation/Foundation.h>
int main (int argc, const char * argv[]) {
@autoreleasepool {
NSString *dateString = @"02/14/2012";
NSDateFormatter *df = [[NSDateFormatter alloc] init];
df.dateFormat = @"MM/dd/yyyy";
NSDate *valentinesDay = [df dateFromString:dateString];
NSLog(@"Valentine's Day = %@", valentinesDay);
NSDateComponents *weekBeforeDateComponents = [[NSDateComponents alloc] init];
weekBeforeDateComponents.week = -1;
NSDate *vDayShoppingDay = [[NSCalendar currentCalendar] dateByAddingComponents:weekBeforeDateComponents toDate:valentinesDay options:0];
超级会员免费看
订阅专栏 解锁全文
391

被折叠的 条评论
为什么被折叠?



