加速度计SensorEvent时间戳 [英] Accelerometer SensorEvent timestamp

查看:1215
本文介绍了加速度计SensorEvent时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即时通讯目前正在对Android应用程序。我必须记录与事件时间的加速度计传感器事件坐标。我得到了传感器事件时间戳,如3497855005850,但我不能够将事件时间戳转换为用户可读的日期时间format.Thanks提前

Im currently working on a android application.. I have to log the accelerometer sensor event coordinate with event time. I got the sensor event timestamp like "3497855005850" but i am not able to convert event timestamp into user readable date time format.Thanks in advance

如何转换SensorEvent时间戳UNIX时间戳?

How can i convert SensorEvent timestamp to unix timestamp?

推荐答案

传感器时间戳实际上是运行时间纳秒的不可以以纳秒系统时间。请参阅<一href="http://stackoverflow.com/questions/3498006/sensorevent-timestamp-to-absolute-utc-timestamp">SensorEvent.timestamp绝对(UTC)时间戳?。

The sensor timestamp is actually nanoseconds of uptime, not system time in nanoseconds. See SensorEvent.timestamp to absolute (utc) timestamp?.

在理论上,你可以使用转换传感器时间戳时间(毫秒):

In theory, you can convert sensor timestamp to time in milliseconds using:

long timeInMillis = (new Date()).getTime() 
                    + (sensorEvent.timestamp - System.nanoTime()) / 1000000L;

您甚至可以在括号(新的日期())。的getTime()有两个 System.nanoTime()调用呼叫和平均它们更贴近实际的偏移量。

You could even bracket the (new Date()).getTime() call with two System.nanoTime() calls and average them to get closer to the actual offset.

然后就可以格式化传感器的时间日期和时间。

Then you can format the sensor time as date and time.

这篇关于加速度计SensorEvent时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆