How to programmatically get the current/local time zone?
13 views (last 30 days)
I want to get the local time zone of the computer that is running my MATLAB function/script. For example, 'America/New_York' or 'America/Chicago' etc. (I want it in that specific format so that I can use it with datetime arrays.)
Calling datetime('now') does not return a time zone.
Is there a way to get the time zone from within MATLAB? Or to somehow read the time zone from Windows itself?
Steven Lord on 30 Nov 2022
Do you want to create a datetime in the current time zone or do you want to know the current time zone? Those are two different tasks, and if you want the former use the 'local' value for the TimeZone option when you construct the datetime object as shown on this documentation page.
t = datetime('now', TimeZone = 'local', Format = 'd-MMM-y HH:mm:ss Z')