2

git commit -m "$(date)" -> is displaying in UTC, but how to get preferred time zone?

I wanted to get preferred timezone in git commit.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
kathik
  • 21
  • 2
  • Does this answer your question? [Bash: get date and time from another time zone](https://stackoverflow.com/questions/26802201/bash-get-date-and-time-from-another-time-zone) – Azeem Jan 18 '23 at 05:12

2 Answers2

2

Strange, considering I always see my commits using my local timezone.
Meaning you do not need to include date output in the commit message itself.

But you can set the TZ environment variable, as seen here to benefit from a display using your timezone.

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

That will show the date of your last commit. In CET timezone.

date inside the commit message:

git commit -m "$(date -d 'TZ="Australia/Sydney"')"
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

You can use the Set Timezone GH Action. This action will set the specified timezone for your GH Runner's machine.

For example:

uses: szenius/set-timezone@v1.1
with:
  timezoneLinux: "Asia/Singapore"
  timezoneMacos: "Asia/Singapore"
  timezoneWindows: "Singapore Standard Time"

Under the hood, it uses the timedatectl (Linux), timezoneMacos (MacOS), or timezoneWindows (Windows) tool to set a timezone depending on your job environment.

This Action should be placed before executing the git commit command and within a single job.

Andrii Bodnar
  • 1,672
  • 2
  • 17
  • 24