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일

1 개 추천

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

Benson Gou
Benson Gou 2020년 7월 13일
Hi, Star,
Thanks for your answer.
My computer time is Not accurate, but I want to obtain the accurate UTC time. How can I do it?
Thanks.
Bensen
Star Strider
Star Strider 2020년 7월 13일
My pleasure.
I have not done this for many years (likely since the early 1990s). However NIST Internet time service , NIST Internet time servers, and NIST TIme Widget are three options.
Back in the 1980s and early 1990s, I had my computer (MS-DOS, early Windows) access those and set my computer clock with them every time I booted it. I wrote my own FORTRAN code to do that (long before I was introduced to MATLAB.) You can probably use the ftp or webread functions (neither of which I have used in the past few years) to get the time. Setting the time may be more of a problem, since I never had to do that in Windows 10 or recent earlier Windows versions. That might require an operating system call.
That is the best I can do.
Benson Gou
Benson Gou 2020년 7월 13일
Hi, Star,
Thanks a lot for your great help.
Benson
Star Strider
Star Strider 2020년 7월 13일
As always, my pleasure!
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일

2 개 추천

utc_time = datetime('now', 'timezone', 'utc')

댓글 수: 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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Calendar에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by