convert time in seconds after midnight to a certain interval

6 visualizaciones (últimos 30 días)
JARED VAHRENBERG
JARED VAHRENBERG el 8 de Nov. de 2020
Respondida: per isakson el 9 de Nov. de 2020
Given the time in seconds after midnight and an interval of what minutes it needs to be rounded to. So for example, if the output of like a datestr function gave 02:07 and my interval was 5 I would need it to be 02:05. How would I do this?
  1 comentario
Mathieu NOE
Mathieu NOE el 9 de Nov. de 2020
hi you need to make modulo(5) of the seconds
seconds_rounded = seconds - mod(seconds,5)

Iniciar sesión para comentar.

Respuestas (1)

per isakson
per isakson el 9 de Nov. de 2020
The script
%%
obj = duration( 0, 0, 2*3600+7*60 );
obj - mod( obj, minutes(5) )
outputs
ans =
duration
02:05:00
>>

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