How to get UTC time in my program?

조회 수: 126 (최근 30일)
Benson Gou
Benson Gou 2020년 7월 12일
댓글: Charalambos Hadjipanayi 2023년 2월 1일
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 CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by