how can I add one minutes in current NSDate of iphone and save in NSDate?

僤鯓⒐⒋嵵緔 提交于 2019-12-01 14:39:11

问题


I can get current date of iphone via this code as

NSDate *currentDate = [NSDate date];
NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init];
[dateFormatter1 setDateFormat:@"yyyy-MM-dd HH:mm"];

NSString *dateString = [dateFormatter1 stringFromDate:currentDate];

Now I just want to increase one mint then save NSString format, how can I?


回答1:


You can use dateByAddingTimeInterval.

NSDate *currentDate = [NSDate date];
NSDate *datePlusOneMinute = [currentDate dateByAddingTimeInterval:60]; 
//60 seconds



回答2:


Or even shorter:

Objective-C

//60 seconds
[NSDate dateWithTimeIntervalSinceNow:60];

Swift

//60 seconds
NSDate(timeIntervalSinceNow: 60)


来源:https://stackoverflow.com/questions/5027902/how-can-i-add-one-minutes-in-current-nsdate-of-iphone-and-save-in-nsdate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!