Android 以Logcat显示的时间
我需要以hh:mm:ss:ss的格式获取Android设备的时间戳。我能够查看Eclipse日志中显示的时间。是电脑时代还是安卓设备时代 如果您需要以编程方式输入设备日期:Android 以Logcat显示的时间,android,time,android-logcat,Android,Time,Android Logcat,我需要以hh:mm:ss:ss的格式获取Android设备的时间戳。我能够查看Eclipse日志中显示的时间。是电脑时代还是安卓设备时代 如果您需要以编程方式输入设备日期: SimpleDateFormat s = new SimpleDateFormat("hh:mm:ss"); String format = s.format(new Date()); 若你们在Android设备上运行你们的应用程序,那个么它将打印设备的时间,若在emulator上,那个么它将显示计算机的时间 为
SimpleDateFormat s = new SimpleDateFormat("hh:mm:ss");
String format = s.format(new Date());
若你们在Android设备上运行你们的应用程序,那个么它将打印设备的时间,若在emulator上,那个么它将显示计算机的时间 为了确保只需将日志时间与设备时间和计算机时间相匹配,您就可以找到答案。从中可以看到,有一个选项可以指定输出的格式() 要获取时间戳,可以使用以下命令
logcat -v time
这将在每条消息前面加上时间戳。取自开发者网站:
时间-显示发出消息的进程的日期、调用时间、优先级/标记和PID
在仿真器上,它将是您的计算机时间,在设备上,它将是您的设备时间…使用终端中的
adb logcat-v threadtime
从设备获取日志,它将包括日期和时间
若要将这些日志重定向到文本文件中,请使用终端中的命令
adb logcat -v threadtime > folder_path_in_the_computer/filename.txt
将long
、threadtime
或time
格式与logcat-v
有许多格式选项,可以传递到命令行中的-v
标志。您可以查看文档中的所有格式
以下是每个选项的示例,您可以决定哪一个适合您的需要:
简介
显示发出消息的进程的优先级、标记和PID
D/StatusBar.NetworkController( 1222): refreshNwBoosterIndicator - setNWBoosterIndicators(false)
D/StatusBar.NetworkController( 1222): refreshNwBoosterIndicator - setNWBoosterIndicators(false)
D( 1222: 1222) refreshNwBoosterIndicator - setNWBoosterIndicators(false)
D( 1222: 1222) refreshNwBoosterIndicator - setNWBoosterIndicators(false)
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)
long
显示所有元数据字段和带有空行的单独消息
(我最喜欢这个,但我喜欢空白。)
过程
仅显示PID
D( 1222) refreshNwBoosterIndicator - setNWBoosterIndicators(false) (StatusBar.NetworkController)
D( 1222) refreshNwBoosterIndicator - setNWBoosterIndicators(false) (StatusBar.NetworkController)
raw
显示原始日志消息,不显示其他元数据字段
refreshNwBoosterIndicator - setNWBoosterIndicators(false)
refreshNwBoosterIndicator - setNWBoosterIndicators(false)
标签
仅显示优先级和标记
D/StatusBar.NetworkController: refreshNwBoosterIndicator - setNWBoosterIndicators(false)
D/StatusBar.NetworkController: refreshNwBoosterIndicator - setNWBoosterIndicators(false)
线程
显示发出消息的线程的优先级、PID和TID的旧格式
D/StatusBar.NetworkController( 1222): refreshNwBoosterIndicator - setNWBoosterIndicators(false)
D/StatusBar.NetworkController( 1222): refreshNwBoosterIndicator - setNWBoosterIndicators(false)
D( 1222: 1222) refreshNwBoosterIndicator - setNWBoosterIndicators(false)
D( 1222: 1222) refreshNwBoosterIndicator - setNWBoosterIndicators(false)
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)
threadtime
显示发出消息的线程的日期、调用时间、优先级、标记、PID和TID
D/StatusBar.NetworkController( 1222): refreshNwBoosterIndicator - setNWBoosterIndicators(false)
D/StatusBar.NetworkController( 1222): refreshNwBoosterIndicator - setNWBoosterIndicators(false)
D( 1222: 1222) refreshNwBoosterIndicator - setNWBoosterIndicators(false)
D( 1222: 1222) refreshNwBoosterIndicator - setNWBoosterIndicators(false)
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)
(文档中说这是默认值,但在我的案例中并非如此。)
时间
显示发出消息的进程的日期、调用时间、优先级、标记和PID
D/StatusBar.NetworkController( 1222): refreshNwBoosterIndicator - setNWBoosterIndicators(false)
D/StatusBar.NetworkController( 1222): refreshNwBoosterIndicator - setNWBoosterIndicators(false)
D( 1222: 1222) refreshNwBoosterIndicator - setNWBoosterIndicators(false)
D( 1222: 1222) refreshNwBoosterIndicator - setNWBoosterIndicators(false)
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
和格式之间的空格,如下所示:
commandLine.add( "-vlong" )
我不知道为什么会这样,但希望这能节省一些人的时间来尝试解决这个问题。我所拍摄的所有logcat日志中都有Android设备的日期和时间。至少从Android 5.x开始,情况就不再是这样了。有趣的是,这已经不存在了。2019年,我得到了:adb logcat-v threadtime adb:用法:未知命令threadtime以“-v time”格式获取年份和日期的任何方法?请帮忙,这不是时间戳