Non-sudo alternatives to get the current time zone?

/etc/localtime is a symlink pointing to the currently used timezone. So you can use

$ readlink /etc/localtime
/var/db/timezone/zoneinfo/Europe/Istanbul
$ readlink /etc/localtime | sed 's#/var/db/timezone/zoneinfo/##g'
Europe/Istanbul

Note: sudo systemsetup -gettimezone prints Time Zone: Europe/Istanbul for me.


Yes, there's an API. The method date(1) uses. You can read the source (freely available), you note the method it uses, you use it in your own program.

Reading the source for date(1) leads to it using the library function fprintftime() in function show_date() which leads to the generic strftime().

https://pubs.opengroup.org/onlinepubs/9699919799/functions/strftime.html