Nslog时间戳

编程入门 行业动态 更新时间:2024-10-08 20:36:26
本文介绍了Nslog时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想对设备运动时间戳属性进行nslog记录.

I want to nslog the device motion timestamp property .

设备运动位于CMMotionManager.devicemotion.timestamp类中

The device motion is in the class CMMotionManager.devicemotion.timestamp

任何想法.

推荐答案

编辑:请参阅Nicolas Lauquin的回答.根据评论,以下解决方案不正确,但保留在此处以作历史记录(并且由于无法将其删除,因为它目前被标记为接受).

Edit: Please see Nicolas Lauquin's answer. Per the comments, the following solution is not correct but is retained here for history (and because I can't delete it since it is currently marked accepted).

timestamp 属性是一个 NSTimeInterval ,因此您应该可以:

The timestamp property is an NSTimeInterval, so you should be able to do:

NSLog(@"Motion at time: %@", [NSDate dateWithTimeIntervalSinceReferenceDate:devicemotion.timestamp]);

NSTimeInterval 只是类型定义的 double 类型,因此您可以使用%f 而不是%@ 并直接记录.

NSTimeInterval is just a typedef'd double type, so you could use %f instead of %@ and log it directly.

此外,文档未指出此时间戳是针对Apple的参考日期还是标准的* nix日期设置的,因此,如果上述方法返回,则可能需要使用 [NSDate dateWithTimeIntervalSince1970:] 日期远在未来.

Also, the docs don't indicate whether this timestamp is set against Apple's reference date or the standard *nix date, so you may need to use [NSDate dateWithTimeIntervalSince1970:] if the aforementioned method returns dates far in the future.

由于@davidbitton建议 CMDeviceMotion 的 timestamp 与上次设备启动有关,因此正确的 NSDate 可以由

As @davidbitton has suggested the CMDeviceMotion's timestamp is relative to the last device boot, the correct NSDate could be derived by

NSDate *startupTime = [NSDate dateWithTimeIntervalSinceNow: -1 * [[NSProcessInfo processInfo] systemUptime]]; NSDate *deviceMotionDate = [NSDate dateWithTimeInterval:devicemotion.timestamp sinceDate:startupTime];

假设@davidbitton是正确的,这应该产生一个大致准确的 NSDate 对象.(参考: NSProcessInfo -systemUptime )

This should yield a roughly accurate NSDate object, assuming @davidbitton is correct. (reference: NSProcessInfo -systemUptime)

但是,鉴于这有多么复杂,我现在为简单起见建议,考虑到 timestamp 属性的性质,您可以将其记录为格式字符串,例如

However, given how complicated this is, I would now suggest for simplicity that, given the nature of the timestamp property, that you log it in a format string as something like

"... event logged at %0.2f seconds since startup...", devicemotion.timestamp

更多推荐

Nslog时间戳

本文发布于:2023-11-22 00:33:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1615289.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时间   Nslog

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!