How to get UTC time in my program?

25 次查看(过去 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

采纳的回答

Star Strider
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
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
Vini Lima 2022-3-25
utc_time = datetime('now', 'timezone', 'utc')
  1 个评论
Charalambos Hadjipanayi
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.

请先登录,再进行评论。

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by