MATLAB Answers

How to get UTC time in my program?

102 views (last 30 days)
Benson Gou
Benson Gou on 12 Jul 2020
Commented: Star Strider on 13 Jul 2020
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 Comments

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 12 Jul 2020
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.
.

  4 Comments

Show 1 older comment
Star Strider
Star Strider on 13 Jul 2020
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 on 13 Jul 2020
Hi, Star,
Thanks a lot for your great help.
Benson
Star Strider
Star Strider on 13 Jul 2020
As always, my pleasure!

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!