How to get UTC time in my program?

132 ビュー (過去 30 日間)
Benson Gou
Benson Gou 2020 年 7 月 12 日
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 件のコメント
Star Strider
Star Strider 2020 年 7 月 13 日
As always, my pleasure!
Charalambos Hadjipanayi
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
Vini Lima 2022 年 3 月 25 日
utc_time = datetime('now', 'timezone', 'utc')
  1 件のコメント
Charalambos Hadjipanayi
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 ExchangeDates and Time についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by