有什么办法可以将nstimeinterval类型值转换为xcode中的字符串类型?
在此先感谢Joy
有点像这样:
@property (nonatomic,assign) NSTimeInterval *startTime;
AVAudioPlayer *player;
Run Code Online (Sandbox Code Playgroud)
我想这样做
if (self.player.currentTime > sub.startTime) {
do something...
}
Run Code Online (Sandbox Code Playgroud)
我认为它们都是NSTimeInterval类型数据,为什么我不能这样做?
如果我像这样更改代码
if (self.player.currentTime > 5) {
do something...
}
Run Code Online (Sandbox Code Playgroud)
它可以很好地工作.
这两个陈述有什么区别
NSDate *today = [NSDate date];
NSDate *tomarow = [today dateByAddingTimeInterval:60*60*24];
NSDate *nextday = [NSDate dateWithTimeInterval:60*60*24 sinceDate:today];
Run Code Online (Sandbox Code Playgroud) 我的意思是12:01:00,12:02:00
在iOS7中,我想在一小段时间改变时调用一个方法.换句话说,如果现在是01:55:47,那么我想在01:56:00 - > 01:57:00 - > 01:58:00调用方法...
我发现调用方法只是关于TimeInterval,但不是我想要的.
我试过这段代码:
NSTimeInterval roundedInterval = round([[NSDate date] timeIntervalSinceReferenceDate] / 60.0) * 60.0;
NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:roundedInterval];
NSTimer *timer = [[NSTimer alloc] initWithFireDate:date
interval:60.0
target:self
selector:@selector(handleEveryMinutes:)
userInfo:nil
repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
- (void)handleEveryMinutes:(NSTimer *)timer {
NSLog(@"one minute!");
}
Run Code Online (Sandbox Code Playgroud)
但是这个方法不会在第二个0调用.
希望很酷的人可以帮助我!
- - - 我的答案 - - - -
我也弄清楚为什么我的代码工作不正常,我需要额外增加60秒到roundedInterval,这是下一分钟的确切时间.如果不添加60秒,则会传递fireDate,因此当我运行我的应用程序时,它必须立即触发.
NSTimeInterval roundedInterval = round([[NSDate date] timeIntervalSinceReferenceDate] / 60.0) * 60.0 + 60; // the extra 60 is used to set the correct …Run Code Online (Sandbox Code Playgroud) 我正在创建一个倒数计时器,我需要打印剩余的时间(小时:分钟:秒)直到特定日期.我已经找到了如何获得Now和目标日期之间的时间间隔,但我不知道如何将时间间隔格式化为字符串.NSDateFormater是否适用于NSTimeInterval?
根据这篇文章, 我应该能够简单地+ =两个NSTimeIntervals ...但我不能.我试图处理秒表上的"暂停"并能够继续使用"运行计数器",以便说出名为totalDuration的NSTimeInterval.但是当我做以下事情时
NSDate *currentDate = [NSDate date];
NSTimeInterval timeInterval = [currentDate timeIntervalSinceDate:startDate];
// Add the saved interval
totalDuration += timeInterval;
Run Code Online (Sandbox Code Playgroud)
我明白了:
.../Views/bdNewTrackViewController.m:506:19: Invalid operands to binary expression ('NSTimeInterval *' (aka 'double *') and 'NSTimeInterval' (aka 'double'))
百思不得其解......
我怎样才能获得像“11:30”这样的时间,以便我想将它与以下内容进行比较:
strOpenTime = @"10:00";
strCloseTime = @"2:00";
Run Code Online (Sandbox Code Playgroud)
那么我怎样才能获得像上面打开/关闭时间格式一样的当前时间,我想要当前时间是否在打开/关闭时间间隔内?
提前致谢..!!
我设置了NSTimer.scheduledTimerWithTimeInterval一个每20分钟有一个间隔的方法.我希望能够找出应用程序进入后台模式时剩余的时间.我如何知道间隔剩余多少时间?
谢谢
我正在完成一个介绍闭包的动画教程。我开始在 Apple 的参考文档中搜索TimeInterval是什么。我很想知道什么是亚毫秒级精度?
我有两个日期时间之间的时差.以秒为单位的间隔是3660,这意味着1小时1分钟前.如何像以前所说的那样以小时和分钟显示秒的间隔?我可以通过这样的工作来获得一小时的工作(3600/60)/60时间,但我如何得到剩余的分钟以及小时?
任何帮助赞赏.
我有NSString有价值" 22/04/2013 05:56",根据要求我只想计算这个时间和日期,并显示一些基于条件的消息.
第一个条件: If(字符串日期=当前日期和字符串时间=当前时间)||(字符串日期=当前日期和字符串时间<当前时间1分钟)
第二个条件: If(String date =当前日期和stringtime>当前时间由多少分钟或小时)
第三个条件:要知道字符串日期是昨天.
第四个条件:To Know是字符串日期是前天.
我从服务器收到这个字符串.如何通过这个"22/04/2013 05:56"字符串实现上述目标.
我有两个带时间间隔数据的字符串.我想添加两个时间间隔并存储到另一个字符串中.这是我的数据
NSString *oldTime=@"00:24"; //Time format is "mm:ss"
NSString *newTime=@"00:07"; //Time format is "mm:ss"
Run Code Online (Sandbox Code Playgroud)
添加两个字符串后,我需要将总时间存储在另一个字符串中,如下所示
NSString *totalTime=oldTime+newTime; //(totalTime=00:31)
Run Code Online (Sandbox Code Playgroud)
我对iOS更新鲜,所以请把这个问题的代码发给我.提前致谢