两种说法有什么区别
NSDate *today = [NSDate date];
NSDate *tomarow = [today dateByAddingTimeInterval:60*60*24];
NSDate *nextday = [NSDate dateWithTimeInterval:60*60*24 sinceDate:today];
两种说法有什么区别
NSDate *today = [NSDate date];
NSDate *tomarow = [today dateByAddingTimeInterval:60*60*24];
NSDate *nextday = [NSDate dateWithTimeInterval:60*60*24 sinceDate:today];
这两种方法的唯一区别是一种是类方法,另一种是实例方法。
以下代码片段演示了这两种方法的使用:
// Today's Date
NSDate *today = [NSDate new];
// Date With Class Method
NSDate *tomorrow1 = [NSDate dateWithTimeInterval:60*60*24 sinceDate:today];
NSLog(@"Date from class method: %@", tomorrow1);
// Date With Instance Method
NSDate *tomorrow2 = [today dateByAddingTimeInterval:60*60*24];
NSLog(@"Date from instance method: %@", tomorrow2);
上面的代码片段将给出如下输出:
上课日期方法:2012-12-27 09:35:15 +0000
来自实例方法的日期:2012-12-27 09:35:15 +0000
有关详细信息,请参阅NSDate