java - 为什么 Java 和 Wireshark 中的时间戳不匹配?

标签 java performance optimization time wireshark

在 Java 中,我通过这种方式获取时间戳:

Date date= new java.util.Date();
return (new Timestamp(date.getTime())).toString();

输出例如:

Start - 2015-02-16 13:59:41.427

然后我将一个数据包写入套接字。

但是,在 Wireshark 中,第一个数据包的日期如下:

62  2015-02-16 13:59:41.421115000   ...

什么???

好吧,我不想让别人告诉我时间戳已关闭。有没有办法改变Java代码,使其产生更符合Wireshark的时间戳?

谢谢

编辑:请求代码

System.err.println("Start - "+currentTimestamp());
int sent = socketChannelOut.write(data);

最佳答案

我怀疑这只是取决于您的系统测量时间的准确性。引用java文档:

"Returns the current time in milliseconds. Note that while the unit of time of the return value is a millisecond, the granularity of the value depends on the underlying operating system and may be larger. For example, many operating systems measure time in units of tens of milliseconds."

由于您看到的差异是 0.005885 秒并且小于 10 毫秒,因此我认为与另一个进程测量时间的比较不会精确到小于 10 毫秒的粒度。也就是说这次你从Java得到的41.427实际上是41.427 +/-10ms

关于java - 为什么 Java 和 Wireshark 中的时间戳不匹配?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28548680/

相关文章:

C++:将一个操作数保存在寄存器中带来了惊人的加速

java - 如何查看 HotSpot 优化后生成的代码?

haskell - 哪种 GHC 优化会导致重复的 case 表达式?

java - eclipse的内容助手正在打开但没有描述

java - Browsermob 导致 IntelliJ 创建的 jar 文件出错

C# 与 C++ 的性能——为什么 .NET 不执行最基本的优化(如死代码消除)?

java - 如何从Java中查找磁盘信息

java - 为什么这种排序在 Solr 中不起作用?

java - 无法读取 https ://spotbugs. github.io/eclipse/content.xml 处的存储库

c# - 从匹配两个单独的 List<T> 中获取 List<T>