【编程技巧】NSDate,NSDateFormatter,NSTimeInterval

//获取日期

todaysDate=[NSDate date];

//显示日期和时间

dateFormat = [[NSDateFormatter alloc] init];//NSDate没有自己的输出,需要借助NSDateFormatter以相应格式输出。

[dateFormat setDateFormat:@”MMMM d,yyyy hh:mm:ssa”];//设置格式

todaysDateString = [dateFormat stringFromDate:todaysDate];//转化成字符串

//计算日期相差多少天

NSTimeInterval difference;

difference = [todaysDate timeIntervalSinceDate:futureDate];

原文地址:https://www.cnblogs.com/ejllen/p/3228117.html