art
art

Reputation: 313

Change timezone display in CentOS 7

I have one silly question on how can I change the date-time in CentOS 7 from this format Thu Jun 4 20:30:43 WIB 2020 to Thu Jun 4 20:33:43 +07 2020. Is this possible? By the way, I'm using timedatectl when I installed CentOS 7.

# date
Thu Jun  4 20:36:46 WIB 2020

change to

# date
Thu Jun  4 20:36:46 +07 2020

I appreciate any help.

Upvotes: 1

Views: 622

Answers (1)

mtnezm
mtnezm

Reputation: 1027

Check your shell's current locale:

locale

Then edit date_fmt variable from the /usr/share/i18n/locales/$YOUR_LOCALE_HERE file accordingly to yours. In this case:

date_fmt "+%a %b %e %H:%M:%S %:z %Y"

And rebuild your localisation files again after the change:

locale-gen

As seen in the date man page it seems that by default only the following time zone formats are supported:

       %z     +hhmm numeric time zone (e.g., -0400)

       %:z    +hh:mm numeric time zone (e.g., -04:00)

       %::z   +hh:mm:ss numeric time zone (e.g., -04:00:00)

       %:::z  numeric time zone with : to necessary precision (e.g., -04, +05:30)

       %Z     alphabetic time zone abbreviation (e.g., EDT)

That means that the previous command will return the following:

Thu Jun  4 20:22:47 +02:00 2020

However, you can always define a custom alias for your date command to exactly show as you want to:

alias date='date "+%a %b %e %H:%M:%S %:z %Y" |sed "s|:00||"'

Add it to your .bashrc file or wherever you store your aliases and you should be fine.

Upvotes: 1

Related Questions