Bookmarks

Running scripts on the ESXi shell with correct time-stamps

While working on the ESXi shell you might notice that the “date” command returns the UTC time instead of displaying the correct time zone like ESX Classic does.

This is by design within ESXi and stated in this VMware KB article: ESXi uses UTC time and does not support changing time zones

Although it’s not supported to change the time zone it could come in handy to get the correct time-stamps for custom scripts within the ESXi Shell.
To get the correct time-stamps you only need to add the following line in the beginning of your script:

export TZ=MET<-/+><no of hours>

In my case UTC is off with -1 hour with the actual time, which means that I need: export TZ=MET-1

Please note that this command only changes the time zone for the current Shell session as long as it’s active, so it doesn’t change the system time zone.
Also don’t forget to check the output with daylight saving time if applicable to your current time zone.