Logcat中显示的时间

时间:2013-02-27 14:07:31

标签: android time android-logcat

我需要以hh:mm:ss:SS格式获取Android设备时间戳。我能够查看Eclipse Logcat中显示的时间。这是计算机的时间还是Android设备的时间?

6 个答案:

答案 0 :(得分:86)

docs of logcat您可以看到有一个选项可以指定输出的格式(-v)。

要获取时间戳,您可以使用命令

logcat -v time

这将为每条消息添加时间戳前缀。

答案 1 :(得分:18)

在终端中使用adb logcat -v threadtime从设备获取日志,它将包括日期和时间。

如果要将这些日志重定向到文本文件,请使用终端中的命令。

 adb logcat -v threadtime > folder_path_in_the_computer/filename.txt

答案 2 :(得分:8)

如果您在Android设备上运行应用程序,那么它将打印设备的时间,如果在模拟器上则会显示计算机的时间。

为了确保只将日志的时间与设备的时间相匹配,并且在计算机的时间内您会找到答案..

答案 3 :(得分:5)

long

使用threadtimetimelogcat -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)

注意:如果您在应用中使用此功能以编程方式收集用户设备日志以发送给支持团队或其他任何内容,则需要省略-vformat之间的空格commandLine.add( "-vlong" ) ,如下:

ag -g <pattern>

不确定为什么会这样,但希望能节省一些时间试图解决这个问题。

答案 4 :(得分:0)

如果您需要以编程方式设置设备日期:

 SimpleDateFormat s = new SimpleDateFormat("hh:mm:ss");
    String format = s.format(new Date());

答案 5 :(得分:0)

取自开发者网站上的Reading and Writing Logs

时间 - 显示发出消息的进程的日期,调用时间,优先级/标记和PID。”

在模拟器上,这将是您的计算机时间,在设备上它将是您设备的时间......