Converting UTC time to seconds
93 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Yogang Singh
le 19 Nov 2020
Commenté : Steven Lord
le 19 Nov 2020
I have a UTC Time stamp on my acquired data in format :
hh:mm:ss.SSSS
This data is taken at 20 ms and I need it to convert to duration in seconds and make a time series of it taking into account the start time and end time (even milli seconds taken into account)
I am currently using :
Dp = duration(hh,mm:mm,ss:ss);
tp= (minutes(D))*60;
Guidance required to make it into a time series which is generic in way that milli seconds are taken into account as well.
0 commentaires
Réponse acceptée
Steven Lord
le 19 Nov 2020
s = '12:34:56.789';
formatSpec = 'hh:mm:ss.SSS';
d = duration(s, 'InputFormat', formatSpec, 'Format', formatSpec)
2 commentaires
Steven Lord
le 19 Nov 2020
Just call seconds.
s = '12:34:56.789';
formatSpec = 'hh:mm:ss.SSS';
d = duration(s, 'InputFormat', formatSpec, 'Format', formatSpec)
format longg
dInSeconds = seconds(d)
To check we can perform the calculations manually. To avoid the "magic numbers" 3600 and 60 I use the capability of MATLAB to convert between double and duration arrays.
secondsPerHour = seconds(hours(1)); % 3600
secondsPerMinute = seconds(minutes(1)); % 60
dInSeconds2 = secondsPerHour*12+secondsPerMinute*34+56.789
Looks pretty good to me.
Plus de réponses (0)
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!