Search code examples
javaandroidshelladb

Compile terminal application for Android shell to record current time?


The date command in epoch time mode only gives seconds resolution when called from inside adb shell on android device (e.g. date +%s.%N returns 14403022.N... so I can only use date +%s)

I need a small terminal program that I can run from adb shell to record a timestamp. I know I can use java methods such as System.currentTimeMillis() and System.nanoTime() from inside my android application to record time.... however, how can I compile a little program that I can just call from adb shell simply to record time values with either System.currentTimeMillis() and System.nanoTime()?


Solution

  • To get current time with high resolution in your android shell scripts use $EPOCHREALTIME built-in shell variable.