Convert day of year to UTC format?

7 visualizaciones (últimos 30 días)
Brandon
Brandon el 14 de Jul. de 2023
Comentada: Brandon el 17 de Jul. de 2023
How would I go about converting this format to matlab UTC format?
ie:
2012-259T01:53:15.50194
2012-259T01:53:16.50194

Respuesta aceptada

Cris LaPierre
Cris LaPierre el 14 de Jul. de 2023
T = ["2012-259T01:53:15.50194";
"2012-259T01:53:16.50194"];
T = datetime(T,'InputFormat','uuuu-DDD''T''HH:mm:ss.SSSSS')
T = 2×1 datetime array
15-Sep-2012 01:53:15 15-Sep-2012 01:53:16
  12 comentarios
Cris LaPierre
Cris LaPierre el 17 de Jul. de 2023
It is a best practice to always pair a hold on with a hold off. You can usually get things to look the way you want without it. The impact is usually later when you rerun your script, or if you create new plots by plotting in the same figure window. It's best to get in the habit while you are learning.
Brandon
Brandon el 17 de Jul. de 2023
Fair enough, thanks again

Iniciar sesión para comentar.

Más respuestas (1)

Rahul
Rahul el 14 de Jul. de 2023
Editada: Rahul el 14 de Jul. de 2023
Hey Brandon,
The date time format provided by you, seemed to in the ISO 8601 format. Breaking down the format:
  • '2012-259': date as year and day of the year. In this case, it indicates the 259th day of the year 2012.
  • 'T': This is a separator indicating the start of the time component.
  • '01:53:15': time in hours, minutes, and seconds. In this case, it indicates 1 hour, 53 minutes, and 15 seconds.
  • '.50194': fractional part of the seconds. In this case, it indicates 50194 milliseconds.
You can use the following snippet to convert it to a standard UTC Timezone format:
inputTime = ['2012-259T01:53:15.50194'; '2012-259T01:53:16.50194'];
dt = datetime(inputTime, 'InputFormat', 'uuuu-DDD''T''HH:mm:ss.SSSSS', 'TimeZone', 'UTC')
dt = 2×1 datetime array
15-Sep-2012 01:53:15 15-Sep-2012 01:53:16
You can refer to the datetime function documentation to further customize the code as per your needs.
Hope that Helped!

Categorías

Más información sobre Data Type Conversion 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