【问题标题】:Can someone show me how to display time + additional minutes in Objective C有人可以告诉我如何在Objective C中显示时间+额外的分钟吗
【发布时间】:2011-04-30 21:03:01
【问题描述】:

假设时间是 15:03。 说变量 minutesToAdd 是 39

在 UILabel 上显示 15:42 的代码是什么(当前时间 + 要添加的分钟数)?

【问题讨论】:

    标签: datetime iphone-sdk-3.0 nsdate nsdateformatter


    【解决方案1】:

    这是一些代码,我没有在 XCode 中检查它(复制/粘贴后不会编译),但想法就像我在下面写的:

    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *dc = [[[NSDateComponents alloc] init] autorelease];
    
    dc.minute = 39;
    
    NSDate *srcDate = NSDate(15:03);   // Create date here
    
    NSDate *resultDate = [calendar dateByAddingComponents:dc toDate:srcDate]; // Here is your new date
    

    【讨论】:

      猜你喜欢
      • 2020-12-25
      • 1970-01-01
      • 2011-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-16
      • 2021-11-16
      • 2011-03-10
      相关资源
      最近更新 更多