Esta página aún no se ha traducido para esta versión. Puede ver la versión más reciente de esta página en inglés.

Fechas y horas

Arreglos de valores de fecha y hora que se pueden visualizar en diferentes formatos

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

expandir todo

Crear arreglos de fecha/hora (datetime)

datetimeArrays that represent points in time
NaTNot-a-Time

Crear arreglos de duración

yearsDuration in years
daysDuration in days
hoursDuration in hours
minutesDuration in minutes
secondsDuration in seconds
millisecondsDuration in milliseconds
durationLengths of time in fixed-length units

Crear arreglos de duración/calendario (calendarDuration)

calyearsCalendar duration in years
calquartersCalendar duration in quarters
calmonthsCalendar duration in months
calweeksCalendar duration in weeks
caldaysCalendar duration in days
calendarDurationLengths of time in variable-length calendar units

Extraer componentes por unidad de tiempo

yearYear number
quarterQuarter number
monthMonth number and name
weekWeek number
dayDay number or name
hourHour number
minuteMinute number
secondSecond number

Dividir en arreglos numéricos

ymdYear, month, and day numbers of datetime
hmsHour, minute, and second numbers of datetime or duration
splitSplit calendar duration into numeric and duration units
timeConvert time of calendar duration to duration
timeofdayElapsed time since midnight for datetimes
isdatetimeDetermine if input is datetime array
isdurationDetermine if input is duration array
iscalendardurationDetermine if input is calendar duration array
isnatDetermine NaT (Not-a-Time) elements
isdstDetermine daylight saving time elements
isweekendDetermine weekend elements
timezonesList time zones
tzoffsetTime zone offset from UTC
betweenCalendar math differences
caldiffCalendar math successive differences
dateshiftShift date or generate sequence of dates and time
isbetweenDetermine elements within date and time interval

Convertir a números

datenumConvert date and time to serial date number
datevecConvert date and time to vector of components
exceltimeConvert MATLAB datetime to Excel date number
juliandateConvert MATLAB datetime to Julian date
posixtimeConvert MATLAB datetime to POSIX time
yyyymmddConvert MATLAB datetime to YYYYMMDD numeric value
addtodateModify date number by field

Convertir a cadenas

charArray de caracteres
stringArray de cadenas 
datestrConvert date and time to string format

Fecha y hora actuales como números o cadena

nowCurrent date and time as serial date number
clockCurrent date and time as date vector
dateCurrent date as character vector

Día de semana o mes en el calendario

calendarCalendar for specified month
eomdayLast day of month
weekdayDay of week

Tiempo transcurrido como número

etimeTime elapsed between date vectors

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.

Compare Dates and Time

You can perform an element-by-element comparison of values in two datetime arrays or two duration arrays using relational operators, such as > and <.

Set Date and Time Display Format

The Format property on datetime, duration, and calendarDuration arrays controls the display of values in each array. You can change the value of this property. Changing the Format property does not change the values in the array, only their display.

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 locals.

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 vice versa, and return unexpected output.