How to get UTC time in my program?
116 views (last 30 days)
Show older comments
Benson Gou on 12 Jul 2020
Commented: Charalambos Hadjipanayi on 1 Feb 2023
I am wondering if it is pissible to get the UTC time in my program. Do I need the internet avaibale if I want to get UTC time?
Thanks a lot.
Star Strider on 12 Jul 2020
dtLCL = datetime('now', 'TimeZone','local') % Current Local Time
dtUTC = datetime(dtLCL, 'TimeZone','Z') % Current UTC Time
That will give you both the local time and the corresponding UTC time.
This gives you a simple network time, which does not rely on local computer time:
url_time = webread('http://worldtimeapi.org/api/timezone/Etc/UTC')
More Answers (1)
Vini Lima on 25 Mar 2022
utc_time = datetime('now', 'timezone', 'utc')
This just converts your local computer time to UTC. So if your local computer time is incorrect for any reason, the utc_time will be also incorrect.
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!