开发者

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

开发者 https://www.devze.com 2023-02-11 05:20 出处:网络
I can get current date of iphone via this code as NSDate *currentDate = [NSDate date]; NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init];

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开发者_Go百科 want to increase one mint then save NSString format, how can I?


You can use dateByAddingTimeInterval.

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


Or even shorter:

Objective-C

//60 seconds
[NSDate dateWithTimeIntervalSinceNow:60];

Swift

//60 seconds
NSDate(timeIntervalSinceNow: 60)
0

精彩评论

暂无评论...
验证码 换一张
取 消