how can I add one minutes in current NSDate of iph

2019-02-21 11:03发布

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?

2条回答
萌系小妹纸
2楼-- · 2019-02-21 11:46

Or even shorter:

Objective-C

//60 seconds
[NSDate dateWithTimeIntervalSinceNow:60];

Swift

//60 seconds
NSDate(timeIntervalSinceNow: 60)
查看更多
兄弟一词,经得起流年.
3楼-- · 2019-02-21 11:52

You can use dateByAddingTimeInterval.

NSDate *currentDate = [NSDate date];
NSDate *datePlusOneMinute = [currentDate dateByAddingTimeInterval:60]; 
//60 seconds
查看更多
登录 后发表回答