Tag: nstimeinterval

这种方法总是给我当天的12:00:00在ios?

是的,这与NSDate开始的一天和一天的结束是类似的,但是这个话题并没有讨论它是否适用于我在这里问的所有情况。 这个问题处理不回正确的价值,因为他们忘了NSDayCalendarUnit。 这个问题正在处理的价值的准确性,因为它原来是不会像我怀疑的DST工作。 在我的应用程序的几个部分,我需要指定一天的时间,而不关心实际的一天,例如,在每天下午4:00做这个活动。 我已经看过几篇关于如何做到这一点的文章,但是希望对我的方法有所反馈。 以下方法旨在返回任何特定日子的午夜,并将与表示特定时间(例如,上午1:00:00为3600)的秒数的偏移一起使用。 我相信它应该可以工作,但是我很好奇它是否会处理像夏时制这样的边缘案例。 对于任何反馈,我们都表示感谢。 谢谢! // We want to return 12:00:00AM of the day represented by the time interval NSTimeInterval getStartOfDay(NSTimeInterval t) { // first convert the time interval to an NSDate NSDate *ourStartingDate = [NSDate dateWithTimeIntervalSinceReferenceDate:t] ; // get just the year, month, and day of our date unsigned unitFlags […]

如何添加多个定时器的输出

我的实用程序应用程序将有20个单独的计时器,如下所示: – (void)updateTimer { NSDate *currentDate = [NSDate date]; NSTimeInterval timeInterval = [currentDate timeIntervalSinceDate:startDate]; NSDate *timerDate = [NSDate dateWithTimeIntervalSince1970:timeInterval]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"mm:ss"]; [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0.0]]; NSString *timeString=[dateFormatter stringFromDate:timerDate]; stopWatchLabel.text = timeString; [dateFormatter release]; } – (IBAction)onStartPressed:(id)sender { startDate = [[NSDate date]retain]; // Create the stop watch timer that fires every […]

如何将5秒添加到计时器

我试图做一个计时器显示以下 – 小时:分钟:秒:毫秒。 这是我的代码: var timer = NSTimer() var startTime = NSTimeInterval() func updateTime() { var currentTime = NSDate.timeIntervalSinceReferenceDate() var elapsedTime : NSTimeInterval = currentTime – startTime let hours = UInt8(elapsedTime / 3600.0) elapsedTime -= (NSTimeInterval(hours) * 3600) let minutes = UInt8(elapsedTime / 60.0) elapsedTime -= (NSTimeInterval(minutes) * 60) let seconds = UInt8(elapsedTime) elapsedTime -= […]

协调CACurrentMediaTime()和deviceCurrentTime

我正在尝试与AVAudioPlayer同步几个CABasicAnimations 。 我遇到的问题是,当AVAudioPlayer使用deviceCurrentTime时, CABasicAnimation使用CACurrentMediaTime()作为调度animation的参考点。 同样对于animation,使用CFTimeInterval ,而对于声音,它是NSTimeInterval (不知道是否像其他CF和NStypes“免费桥接”)。 我发现参考点也是不同的。 有没有办法确保声音和animation使用相同的参考点?

实际上使用UIDatePickerModeCountDownTimer作为一个计时器

我只是想做一个计时器。 我想使用UIDatePickerModeCountDownTimer模式,这样当用户在select器中简单地select15分钟时,它们会被传回到一个屏幕上,在一个标签中显示15分钟的值,然后他们可以从中倒计时。 正如我试图从DatePicker获取值,我意识到,select器传递回NSTimeInterval获取当前时间在几秒钟内: UIDatePicker *pickerView = [[UIDatePicker alloc] init]; NSTimeInterval new = (NSTimeInterval)pickerView.countDownDuration; 所以我只想知道用户select的价值,而不是以秒为单位的当前时间。 我正试图从UIActionSheet中提交的DatePicker中传回这些数据…对于正在发生什么或者我做错了什么想法? 我只想要一个计时器!!!!!!!

如何从上次启动获取NSTimeInterval值

我需要从上次设备启动获取NSTimeInterval值。 我发现适合这个任务的CACurrentMediaTime(),但在我的应用程序中,我没有使用核心animation,我不认为这是包括这个框架只是为了得到这个function的最好方法。 有没有另一种方式,从上次开机更快捷的方式获得时间?

如何在X秒后更改NSTimer的NSTimeInterval?

我正在快速制作一个有两个定时器的应用程序。 10秒后,我想另一个计时器去更快。 我试过这样做,但它没有工作(我试图改变无功time为1): @IBOutlet var displayTimeLabel: UILabel! var startTimer = NSTimeInterval() var timer = NSTimer() var timer2:NSTimer = NSTimer() var time = 2.0 @IBAction func Start(sender: UIButton) { if !timer2.valid { timer2 = NSTimer.scheduledTimerWithTimeInterval(0.01, target: self, selector: "updateTime", userInfo: nil, repeats: true) startTimer = NSDate.timeIntervalSinceReferenceDate() } timer = NSTimer.scheduledTimerWithTimeInterval(time, target: self, selector: "timer:", userInfo: nil, […]

在iOS中将date转换为时间戳

你如何将任何给定的date转换为毫秒? 例如,2014-01-23到时间戳转换。 NSDate *date = [dateFormatter dateFromString:@"2014-01-23"]; NSLog(@"date=%@",date); NSTimeInterval interval = [date timeIntervalSince1970]; NSLog(@"interval=%f",interval); NSDate *methodStart = [NSDate dateWithTimeIntervalSince1970:interval]; [dateFormatter setDateFormat:@"yyyy/mm/dd "]; NSLog(@"result: %@", [dateFormatter stringFromDate:methodStart]); 产出成果:1970/30/01

如何将NSTimeInterval转换为int?

如何将NSTimeInterval转换为整数值? 我的TimeInterval值为83.01837 。 我需要把它转换成83 。 我GOOGLE了,但找不到任何帮助。

从NSDate中减去分钟数

我想减去一些分钟15分钟10分钟等等,而我现在有date对象,现在我想减去分钟。