Fechas y horas
Los tipos de datos de fecha y hora datetime
, duration
y calendarDuration
admiten cálculos eficientes, comparaciones y visualizaciones con formato de fechas y horas. Trabaje con estos arreglos de la misma forma que trabaja con los arreglos numéricos. Puede agregar, sustraer, ordenar, comparar, concatenar y representar gráficamente valores de fecha y hora. También puede representar fechas y horas como arreglos numéricos o como texto. Para obtener más información, consulte Represent Dates and Times in MATLAB o vea Arreglos de fecha y hora.
Funciones
Temas
- Represent Dates and Times in MATLAB
Use
datetime
arrays to store date and time information. These arrays support arithmetic, sorting, comparisons, plotting, and formatted display. - Replace Discouraged Instances of Serial Date Numbers and Date Strings
As of R2022b, serial date numbers and date strings are not recommended for specifying dates and times. Use the
datetime
,duration
, andcalendarDuration
data types instead. Follow these recommendations for updating your code. - Comparar fechas y horas
Puede realizar una comparación de valores elemento por elemento en dos arreglos
datetime
o dos arreglosduration
mediante operadores relacionales, como>
y<
. - Establecer el formato de visualización de fechas y horas
La propiedad
Format
en los arreglosdatetime
,duration
ycalendarDuration
controla la visualización de los valores de cada arreglo. Puede cambiar el valor de esta propiedad. Cambiar la propiedadFormat
no cambia los valores del arreglo, solo su visualización. - Specify Time Zones
When you create a datetime, it is unzoned by default. If you work with datetime values from multiple time zones or need to account for daylight saving time, you might need to specify a time zone.
- Share Code and Data Across Locales
Follow these best practices when sharing code that handles dates and time with MATLAB® users in other locales. Write and read dates from other locales.
- Core Functions Supporting Date and Time Arrays
Many functions in MATLAB operate on date and time arrays in much the same way that they operate on other arrays.
Solución de problemas
Carryover in Date Vectors and Strings
If an element falls outside the conventional range, MATLAB adjusts both that date vector element and the previous element.
Converting Date Vector Returns Unexpected Output
Because a date vector is a 1-by-6 vector of numbers, datestr
might interpret your input date vectors as vectors of serial date numbers—or interpret
serial date numbers as date vectors—and return unexpected output.