Timestamp from Android device in the format hh:mm:ss:SS

大兔子大兔子 提交于 2019-12-04 06:20:20

问题


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);

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?

Thanks in advance!


回答1:


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...



来源:https://stackoverflow.com/questions/14890388/timestamp-from-android-device-in-the-format-hhmmssss

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!