来自Android设备的时间戳,格式为hh:mm:ss:SS [英] Timestamp from Android device in the format hh:mm:ss:SS

查看:192
本文介绍了来自Android设备的时间戳,格式为hh:mm:ss:SS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Android中记录传感器数据.为了将值存储在数据库中,我需要将时间戳记作为主键,格式为hh:mm:ss:SS,其中SS表示毫秒值.当我尝试使用SensorEvent.timestamp(使用下面的代码)时,无法从Date类获取毫秒.

I have a requirement to log the sensor data in Android. In order to store the values in a Database, I need the timestamp as primary key in the format - hh:mm:ss:SS, where SS represents millisecond value. When I tried to use SensorEvent.timestamp(using the code below), I was unable to get the millisecond from Date class.

    long currTimeRelativeToBoot = SystemClock.uptimeMillis();
    long currTimeAbsolute = System.currentTimeMillis();
    double mStartTimeAbsoluteS = ((double)(currTimeAbsolute - currTimeRelativeToBoot))/(double)1000.0;
    double temp = mStartTimeAbsoluteS+((double)event.timestamp)/1000000000.0;
    Date time=new java.util.Date((long)temp*1000);

是否可以通过hh:mm:ss:SS格式从Android设备获取当前时间? 或替代方法是什么?

Is it possible to get the current time from the Android device in the format hh:mm:ss:SS? Or what is the alternative for this?

提前谢谢!

推荐答案

使用SimpleDateFormat,请参见教程此处.但是不建议您使用这种方法,如果您将其保存为很长的时间,则可以对其进行比较,订购等...

use SimpleDateFormat, see tutorial here. But it's not recommended this approach, if you save it as a long, you can compare it, order, etc...

这篇关于来自Android设备的时间戳,格式为hh:mm:ss:SS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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