2012-06-28 99 views
1

在JGit中,如何獲取提交的時區? 當前RevCommit類沒有關於時區的任何信息。 它只返回UTC UNIX時間JGit獲取提交時區

+0

爲什麼你認爲時區存儲在提交?特別是如你所說,時間存儲在UTC? – meagar

+0

是的,時區也存儲在提交對象中。你能看到「-0700」在http://git-scm.com/book/en/Git-Internals-Git-Objects#Commit-Objects – linquize

回答

2

使用PersonIdent:

RevCommit commit = ...; 
PersonIdent committerIdent = commit.getCommitterIdent(); 
if (committerIdent != null) { 
    TimeZone timeZone = committerIdent.getTimeZone(); // or getTimeZoneOffset() 
} 

還有getAuthorIdent()這是筆者一樣的。