在 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/