我需要在Android中记录传感器数据。为了将值存储在数据库中,我需要将时间戳作为主键,格式为hh:mm:ss:SS,其中SS表示毫秒值。当我尝试使用SensorEvent.timestamp(使用下面的代码)时,我无法从Date类获得毫秒。
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设备获取当前时间? 或者替代方案是什么?
提前致谢!