Published on

How to Use Custom Timezone in Date CLI Command

Authors

At work, we've started using Calendar Versioning for one of our projects.

We've decided to use the following pattern for the version → YYYY.MM.DD-HH.MM (UTC by default)

currentDate=`date +"%Y.%m.%d-%H.%M"`
echo $currentDate

But as soon as we've started using it, we've noticed that it's hard (mentally) to differentiate old and new version based on UTC.

And so we've configured it to use a Indian Standard Timezone(IST).

Solution

Here's how we've done it:

currentDate=TZ=':Asia/Calcutta' date +"%Y.%m.%d-%H.%M"
echo $currentDate

And you can refer to list of tz database time zones to figure out your TZ value.