我正在使用 SVNKit 从 SVN 服务器检索日志。我使用的是 SVNKit 版本 1.3.2。
除了我最近看到的一些奇怪的问题之外,一切都运行良好。提交日期检索正在转换为运行程序的系统的时区,从而引入偏移量,从而更改日志(使用 tortoise svn)和程序输出中看到的时间。
logEntries = (Collection)repository.log(new String[] {""}, null, startRevision, endRevision, true, true);
for (SVNLogEntry entry : logEntries) {
Date date = entry.getDate();
...
...
}
我想要的是日期输出应该与 SVN 日志中看到的相同。
最佳答案
您实际上并未展示如何“输出”日期,这可能是此处的相关代码段。我猜你使用了toString()
。
java.util.Date
对象将时间存储为 1970 年 1 月 1 日 00:00:00 GMT 之后的偏移量(以毫秒为单位)。 toString
will convert that to the local timezone以及更友好的格式。
要打印 UTC 时间,请尝试以下操作:
TimeZone utc = TimeZone.getTimeZone("GMT:00");
DateFormat dateFormat = DateFormat.getTimeInstance(DateFormat.LONG);
dateFormat.setTimeZone(utc);
System.out.println(dateFormat.format(date));
What I want is the date output should be same as what is seen in the SVN Logs"
据我所知,您在 SVN 客户端中“看到”的内容也会转换为本地时区,而 SVN 在内部以 UTC 时区存储提交时间。这是正确的做法;所有软件都应该以这种方式处理时间数据。如果您显示其他内容,您应该通过清楚地显示时区信息来通知用户。
关于java - 使用 SVNKit 从 SVN 提取的日期不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4582530/