How to get UTC time in my program?
94 次查看(过去 30 天)
显示 更早的评论
Dear All,
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.
Benson
0 个评论
采纳的回答
Star Strider
2020-7-12
Try this:
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.
.
5 个评论
Charalambos Hadjipanayi
2023-2-1
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')
更多回答(1 个)
Vini Lima
2022-3-25
utc_time = datetime('now', 'timezone', 'utc')
1 个评论
Charalambos Hadjipanayi
2023-2-1
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!