How to get UTC time in my program?
115 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Benson Gou
le 12 Juil 2020
Commenté : Charalambos Hadjipanayi
le 1 Fév 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
0 commentaires
Réponse acceptée
Star Strider
le 12 Juil 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 commentaires
Charalambos Hadjipanayi
le 1 Fév 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')
Plus de réponses (1)
Vini Lima
le 25 Mar 2022
utc_time = datetime('now', 'timezone', 'utc')
1 commentaire
Charalambos Hadjipanayi
le 1 Fév 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.
Voir également
Catégories
En savoir plus sur Dates and Time dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!