问题
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