How to get UTC time in my program?

126 visualizaciones (últimos 30 días)
Benson Gou
Benson Gou el 12 de Jul. de 2020
Comentada: Charalambos Hadjipanayi el 1 de Feb. de 2023
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

Respuesta aceptada

Star Strider
Star Strider el 12 de Jul. de 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.
.
  5 comentarios
Star Strider
Star Strider el 13 de Jul. de 2020
As always, my pleasure!
Charalambos Hadjipanayi
Charalambos Hadjipanayi el 1 de Feb. de 2023
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')

Iniciar sesión para comentar.

Más respuestas (1)

Vini Lima
Vini Lima el 25 de Mzo. de 2022
utc_time = datetime('now', 'timezone', 'utc')
  1 comentario
Charalambos Hadjipanayi
Charalambos Hadjipanayi el 1 de Feb. de 2023
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by