jjzjj

NSTimeinterval

全部标签

ios - 如何在 Swift 中使用 Timer(以前称为 NSTimer)?

我试过了vartimer=NSTimer()timer(timeInterval:0.01,target:self,selector:update,userInfo:nil,repeats:false)但是,我得到一个错误提示'(timeInterval:$T1,target:ViewController,selector:()->(),userInfo:NilType,repeats:Bool)->$T6'isnotidenticalto'NSTimer' 最佳答案 这将起作用:overridefuncviewDidLoad(){

ios - 如何在 Swift 中使用 Timer(以前称为 NSTimer)?

我试过了vartimer=NSTimer()timer(timeInterval:0.01,target:self,selector:update,userInfo:nil,repeats:false)但是,我得到一个错误提示'(timeInterval:$T1,target:ViewController,selector:()->(),userInfo:NilType,repeats:Bool)->$T6'isnotidenticalto'NSTimer' 最佳答案 这将起作用:overridefuncviewDidLoad(){

swift - 在 swift 中将 double 值四舍五入到 x 小数位

谁能告诉我如何在Swift中将double值四舍五入到x位小数?我有:vartotalWorkTimeInHours=(totalWorkTime/60/60)totalWorkTime是一个以秒为单位的NSTimeInterval(double)。totalWorkTimeInHours会给我小时数,但它会给我时间量,而且是这么长的精确数字,例如1.543240952039……当我打印totalWorkTimeInHours时,如何将它四舍五入到1.543? 最佳答案 您可以使用Swift的round函数来完成此操作。要以3位精度

swift - 在 swift 中将 double 值四舍五入到 x 小数位

谁能告诉我如何在Swift中将double值四舍五入到x位小数?我有:vartotalWorkTimeInHours=(totalWorkTime/60/60)totalWorkTime是一个以秒为单位的NSTimeInterval(double)。totalWorkTimeInHours会给我小时数,但它会给我时间量,而且是这么长的精确数字,例如1.543240952039……当我打印totalWorkTimeInHours时,如何将它四舍五入到1.543? 最佳答案 您可以使用Swift的round函数来完成此操作。要以3位精度

ios - NSDate 返回一个负的 NSTimeInterval

我有以下代码:-(void)pointsStartedDisplaying{staticdispatch_once_tonceToken;dispatch_once(&onceToken,^{dispatch_async(dispatch_get_main_queue(),^{self.timeStartedDisplayingPoint=[NSDatedate];self.stopButton.enabled=YES;[NSTimerscheduledTimerWithTimeInterval:1.0target:selfselector:@selector(updateElapse

objective-c - NSDate 的 dateWithTimeIntervalSinceNow 中的负 NSTimeInterval :

FromtheiOSdocs:secondsThenumberofsecondsfromthecurrentdateandtimeforthenewdate.Useanegativevaluetospecifyadatebeforethecurrentdate.但是这段代码给出的日期是2148年:#import#importintmain(intargc,constchar*argv[]){@autoreleasepool{for(inti=0;i它应该生成最近的半随机日期和时间。 最佳答案 正如HotLicks所说,这是由于在使数

ios - 直接从 NSTimeInterval 到 NSDateComponents 到 NSString 转换?

我有几个NSTimeInterval是从以前对各种NSDate的计算得出的。现在我想以days:hours:minutes:seconds格式向用户显示这些间隔。在我的应用程序的早期,我使用此代码在略有不同的上下文中显示信息:-(void)updateDurationLabel{//WhichcalendarNSCalendar*calendar=[NSCalendarcurrentCalendar];//GetsthecomponentizedintervalfromthemostrecenttimeanactivitywastappeduntilnowNSDateComponent

iphone - 如何从上次启动中获取 NSTimeInterval 值

我需要从上次设备启动中获取NSTimeInterval值。我发现CACurrentMediaTime()适合这个任务,但在我的应用程序中我没有使用CoreAnimation,我不认为这是为了获得这个功能而包含这个框架的最好方法。有没有另一种方法可以更优雅地从上次启动开始以秒为单位获取时间? 最佳答案 自上次系统重启以来的NSTimeInterval值可以通过以下Foundation对象和方法更直接地获取:[[NSProcessInfoprocessInfo]systemUptime] 关

iOS 错误 "Initializing ' NSTimeInterval *' (aka ' 双 *')

我正在尝试获取两个NSDate之间的时间间隔,即previousActivity.stopTime和previousActivity.startTime。我收到此代码的错误:NSTimeInterval*previousActivityDuration=[previousActivity.stopTimetimeIntervalSinceDate:previousActivity.startTime];这是错误信息:“使用不兼容类型‘NSTimeInterval’(又名‘double’)的表达式初始化‘NSTimeInterval*’(又名‘double*’)”我不明白;如果NSTim

ios - NSTimeInterval 到 unix 时间戳

我正在从CMMotionManager获取CMDeviceMotion对象。CMDeviceMotion的属性之一是时间戳,表示为NSTimeInterval(double)。根据文档,这允许“亚毫秒”时间戳精度。[motionManagerstartDeviceMotionUpdatesToQueue:motionQueuewithHandler:^(CMDeviceMotion*motion,NSError*error){NSLog(@"Sample:%dTimestamp:%f",counter,motion.timestamp);}不幸的是,NSTimeInterval是自上次