How to measure time from adb shell with milliseconds resolution?

爷,独闯天下 提交于 2019-11-27 15:34:51

mksh (the standard Android shell since version 4.0) has a built-in EPOCHREALTIME environment variable:

Time since the epoch, as returned by gettimeofday(2), formatted as decimal tv_sec followed by a dot . and tv_usec padded to exactly six decimal digits.

So the command to get epoch time with microsecond accuracy in Windows would be:

adb shell echo $EPOCHREALTIME

or in Linux:

adb shell 'echo $EPOCHREALTIME'

If you just need millisecond accuracy:

adb shell 'echo ${EPOCHREALTIME:0:14}'

Or just the milliseconds part to use with another time format:

adb shell 'echo $(date +%T)${EPOCHREALTIME:10:4}'

Kind of solved my problem by using botbrew. Probably not idea, but at least it works for now. /data/botbrew-basil/init -- date +%s.%N -- returns nanosecond resolution.

adb shell echo $EPOCHREALTIME gives you the time with micro seconds, (don't write it with '\' before the variable name)

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