0

I am using SVNKit to retrieve logs from a SVN server. I am using SVNKit version 1.3.2.

Everything is working fine and well except for some bizarre problem that I have been seeing lately. The commit date retrieve is getting converted to the timezone of the system running the program and thus introduces an offset thus changing the time whats seen in the logs (using tortoise svn) and in output of my program.


logEntries = (Collection)repository.log(new String[] {""}, null, startRevision, endRevision, true, true);
for (SVNLogEntry entry : logEntries) {
    Date date = entry.getDate();
    ...
    ...
}

What I want is the date output should be same as what is seen in the SVN Logs.

1 Answer 1

2

You don't actually show how you "output" the date, which is probably the relevant piece of code here. I'll guess that you use toString().

A java.util.Date object stores time as an offset in milliseconds after January 1, 1970. 00:00:00 GMT. toString will convert that to the local timezone and a friendlier format.

To print the UTC time, try this instead:

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"

AFAIK what you "see" in a SVN client is also converted to the local timezone, while internally SVN stores the commit time in the UTC timezone. This is the right thing to do; all software should treat time data in this manner. If you show anything else, you should inform the user by clearly showing the timezone information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.