git: timezone and timestamp format

GitTimezoneFormatTimestampTimezone Offset

Git Problem Overview


From git I can get the timestamp:

"2011-10-04 12:58:36 -0600"

but is there any way to show it as:

"2011-10-04 06:58:36"

So all I want is to get rid of the -0600 timezone offset. How can I do this? Thanks.

Git Solutions


Solution 1 - Git

If you ask about git log, you can try and select most correct form from:

git log --date={relative,local,default,iso,rfc}

--date=local seems to be the best candidate.

To make this permanent, use git config --global log.date local.

Solution 2 - Git

TZ=UTC git log --date=local

in order to get non-local-timezone one-timezone output.

Solution 3 - Git

git log --date=local

Does the trick.

git config --global log.date local

Solution 4 - Git

Unfortunately, using git log --date=local as explained in previous answers changes the output format.

To keep the format as asked (YYYY-MM-DD HH:mm) I had to use:

git log --date=iso-local

But that only works on git 2.7 or above.

Solution 5 - Git

To get the format (YYYY-MM-DD HH:hh), you can use:

git log --date=format:%Y-%m-%d\ %H:%M

Works beautifully with Git Standup too: https://github.com/kamranahmedse/git-standup

Solution 6 - Git

A full command line answer:

TZ=GMT git show -s --format=%cd --date=iso-local

Solution 7 - Git

jveerman's post was really helpful: > If you want to display the git date in YYYY-MM-DD HH:MM:SS format:

DATE=$(git log -n 1 --pretty=format:"%ad" --date=iso)
echo "Date: ${DATE::20}"

For log format I was able to add this

[log]
date=format:%Y-%m-%d %H:%M:%S

to my ~/.gitconfig

but getting the same nicely formatted date/time added automatically to my commit messages was an ordeal. I found nothing helpful until I added this to the .git/hooks/prepare-commit-msg file:

DATE=$(git log -n 1 --pretty=format:"%ad" --date=iso)
echo "${DATE::20}" >> $1

If you're mainly using the Desktop app, it's lovely to have the exact time of change shown with the commit listing!

Is there any way to make this global, so I don't have to edit each local repo's prepare-commit-msg file ?

Solution 8 - Git

If you want to display the git date in YYYY-MM-DD HH:MM:SS format:

DATE=$(git log -n 1 --pretty=format:"%ad" --date=iso)
echo "Date: ${DATE::20}"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSandyBrView Question on Stackoverflow
Solution 1 - GitLazy BadgerView Answer on Stackoverflow
Solution 2 - GitChristianView Answer on Stackoverflow
Solution 3 - GitbondView Answer on Stackoverflow
Solution 4 - GitFabio MarrecoView Answer on Stackoverflow
Solution 5 - GitWill WrightView Answer on Stackoverflow
Solution 6 - GitKevin EnglishView Answer on Stackoverflow
Solution 7 - GitpapaJupeView Answer on Stackoverflow
Solution 8 - GitjveermanView Answer on Stackoverflow