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

前端 未结 2 859
长情又很酷
长情又很酷 2021-01-17 11:15

I can get current date of iphone via this code as

NSDate *currentDate = [NSDate date];
NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init];
[da         


        
相关标签:
2条回答
  • 2021-01-17 11:40

    You can use dateByAddingTimeInterval.

    NSDate *currentDate = [NSDate date];
    NSDate *datePlusOneMinute = [currentDate dateByAddingTimeInterval:60]; 
    //60 seconds
    
    0 讨论(0)
  • 2021-01-17 11:52

    Or even shorter:

    Objective-C

    //60 seconds
    [NSDate dateWithTimeIntervalSinceNow:60];
    

    Swift

    //60 seconds
    NSDate(timeIntervalSinceNow: 60)
    
    0 讨论(0)
提交回复
热议问题