【发布时间】:2013-02-27 14:07:31
【问题描述】:
我需要获取格式为 hh:mm:ss:SS 的 Android 设备时间戳。我可以查看 Eclipse 的 Logcat 中显示的时间。是电脑的时间还是安卓设备的时间?
【问题讨论】:
-
在我获取的所有 logcat 日志中,这是 Android 设备的日期和时间。
标签: android time android-logcat
我需要获取格式为 hh:mm:ss:SS 的 Android 设备时间戳。我可以查看 Eclipse 的 Logcat 中显示的时间。是电脑的时间还是安卓设备的时间?
【问题讨论】:
标签: android time android-logcat
【讨论】:
在终端使用adb logcat -v threadtime从设备获取日志,它将包括日期和时间。
如果您想将这些日志重定向到文本文件中,请在终端中使用命令。
adb logcat -v threadtime > folder_path_in_the_computer/filename.txt
【讨论】:
如果您在 Android 设备上运行您的应用程序,那么它将打印设备的时间,如果在模拟器上,它将显示计算机的时间。
为了确保将日志的时间与设备的时间和计算机的时间相匹配,您会找到答案..
【讨论】:
long、threadtime 或time 格式与logcat -v <format>
logcat 有许多格式选项,可以在命令行中传递给-v 标志。您可以查看文档here中的所有格式。
以下是每个选项的示例,以便您决定哪一个适合您的需求:
brief显示发出消息的进程的优先级、标签和PID。
D/StatusBar.NetworkController( 1222): refreshNwBoosterIndicator - setNWBoosterIndicators(false)
D/StatusBar.NetworkController( 1222): refreshNwBoosterIndicator - setNWBoosterIndicators(false)
long显示所有元数据字段并用空行分隔消息。
(我最喜欢这个,但我很喜欢空白。)
[ 01-27 13:17:07.703 1222: 1222 D/StatusBar.NetworkController ]
refreshNwBoosterIndicator - setNWBoosterIndicators(false)
[ 01-27 13:17:07.703 1222: 1222 D/StatusBar.NetworkController ]
refreshNwBoosterIndicator - setNWBoosterIndicators(false)
process仅显示 PID。
D( 1222) refreshNwBoosterIndicator - setNWBoosterIndicators(false) (StatusBar.NetworkController)
D( 1222) refreshNwBoosterIndicator - setNWBoosterIndicators(false) (StatusBar.NetworkController)
raw显示没有其他元数据字段的原始日志消息。
refreshNwBoosterIndicator - setNWBoosterIndicators(false)
refreshNwBoosterIndicator - setNWBoosterIndicators(false)
tag只显示优先级和标签。
D/StatusBar.NetworkController: refreshNwBoosterIndicator - setNWBoosterIndicators(false)
D/StatusBar.NetworkController: refreshNwBoosterIndicator - setNWBoosterIndicators(false)
thread显示发出消息的线程的优先级、PID 和 TID 的传统格式。
D( 1222: 1222) refreshNwBoosterIndicator - setNWBoosterIndicators(false)
D( 1222: 1222) refreshNwBoosterIndicator - setNWBoosterIndicators(false)
threadtime显示发出消息的线程的日期、调用时间、优先级、标签、PID和TID。
(文档说这是默认设置,但在我的情况下并非如此。)
01-27 13:17:07.703 1222 1222 D StatusBar.NetworkController: refreshNwBoosterIndicator - setNWBoosterIndicators(false)
01-27 13:17:07.703 1222 1222 D StatusBar.NetworkController: refreshNwBoosterIndicator - setNWBoosterIndicators(false)
time显示发出消息的进程的日期、调用时间、优先级、标签和PID。
01-27 13:17:07.703 D/StatusBar.NetworkController( 1222): refreshNwBoosterIndicator - setNWBoosterIndicators(false)
01-27 13:17:07.703 D/StatusBar.NetworkController( 1222): refreshNwBoosterIndicator - setNWBoosterIndicators(false)
注意:如果您在应用程序中使用它来以编程方式收集用户的设备日志以发送给您的支持团队或其他什么,您需要省略 -v 和 @ 之间的空格987654346@,像这样:
commandLine.add( "-vlong" )
不知道为什么会这样,但希望可以节省一些时间来解决这个问题。
【讨论】:
取自开发者网站上的Reading and Writing Logs:
"时间 — 显示发出消息的进程的日期、调用时间、优先级/标签和 PID。"
在模拟器上是您的计算机时间,在设备上是您设备的时间...
【讨论】:
如果您以编程方式需要设备日期:
SimpleDateFormat s = new SimpleDateFormat("hh:mm:ss");
String format = s.format(new Date());
【讨论】: