Reputation: 51
git commit -m "$(date)"
-> is displaying in UTC, but how to get preferred time zone?
I wanted to get preferred timezone in git commit
.
Upvotes: 5
Views: 1879
Reputation: 2202
EDIT 2024-02-23
Suggested action is not maintained anymore. I've made a fork and will keep it up-to-date.
https://github.com/marketplace/actions/timezoneaction
uses: MathRobin/[email protected]
with:
timezoneLinux: 'Asia/Singapore'
timezoneMacos: 'Europe/Paris'
timezoneWindows: 'W. Central Africa Standard Time'
Fully compatible with previous package.
Action from szenius is using node 16 which is deprecated and will not be usable during Spring 2024: https://github.blog/changelog/2023-09-22-github-actions-transitioning-from-node-16-to-node-20/
Our plan is to transition all actions to run on Node 20 by Spring 2024.
Older deprecated solution
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/[email protected]
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.
Upvotes: 2
Reputation: 1328322
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"')"
Upvotes: 3