Main Content

La traduzione di questa pagina non è aggiornata. Fai clic qui per vedere l'ultima versione in inglese.

Date e orario

Array di valori data e orario visualizzabili in diversi formati

I tipi di dati data e orario datetime, duration e calendarDuration supportano efficientemente i calcoli, i confronti e la visualizzazione formattata di date e orari. Si può lavorare con questi array nello stesso modo in cui si lavora con gli array numerici. È possibile quindi addizionare, ordinare, confrontare, concatenare e tracciare i valori data e orario. È inoltre possibile rappresentare le date e gli orari come array numerici o come testo. Per maggiori informazioni, vedere Represent Dates and Times in MATLAB o guardare Date and Time Arrays (Array di data e orario).

Funzioni

espandi tutto

Punti nel tempo

datetimeArrays that represent points in time
dateshiftShift date or generate sequence of dates and times
NaTNot-a-Time
eomdayLast day of month
lweekdate(Not recommended; use dateshift) Date of last occurrence of weekday in month
nweekdate(Not recommended; use dateshift) Date of specific occurrence of weekday in month

Durate

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

Durate di calendario

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

Calendario del mese

calendarCalendar for specified month

Punti nel tempo in formati alternati

datenum(Not recommended; use datetime or duration) Convert date and time to serial date number
now(Not recommended; use datetime) Current date and time as serial date number
clock(Not recommended; use datetime) Current date and time as date vector
date(Not recommended; use datetime("today")) Current date as character vector
today(Not recommended; use datetime("today")) Current date
eomdate(Not recommended; use dateshift) Last date of month

Estrazione dei componenti

yearYear number of input date and time
quarterQuarter number of input date and time
monthMonth number or name of input date and time
weekWeek number of input date and time
dayDay number or name of input date and time
weekdayDay of week
hourHour component of input date and time
minuteMinute component of input date and time
secondSeconds component of input date and time
weeknum(Not recommended; use week) Week in year

Divisione in componenti

ymdYear, month, and day numbers of datetime
hmsHour, minute, and second numbers of datetime or duration
datevecConvert date and time to vector of components
splitSplit calendar duration into numeric and duration units
timeConvert time of calendar duration to duration
timeofdayElapsed time since midnight for datetime arrays

Array datetime

betweenCalendar math differences
caldiffCalendar math successive differences
tzoffsetTime zone offset from UTC
dateshiftShift date or generate sequence of dates and times

Array in formato fisso

addtodate(Not recommended; use duration or calendarDuration) Add time to serial date number
etime(Not recommended; use datetime values or between) Time elapsed between date vectors
months(Not recommended; use between) Number of whole months between dates
isbetweenDetermine which elements are within specified range
isregularDetermine if input times are regular with respect to time or calendar unit
isnatDetermine NaT (Not-a-Time) elements
isdstDetermine daylight saving time elements
isweekendDetermine weekend elements
isdatetimeDetermine if input is datetime array
isdurationDetermine if input is duration array
iscalendardurationDetermine if input is calendar duration array
stringString array
charCharacter array
datestr(Not recommended; use string or char) Convert date and time to string format

Conversioni

convertToConvert datetime values to numeric representations
exceltimeConvert MATLAB datetime to Excel date number
posixtimeConvert MATLAB datetime to POSIX time
juliandateConvert MATLAB datetime to Julian date
yyyymmddConvert MATLAB datetime to YYYYMMDD numeric value
m2xdate(Not recommended; use exceltime) MATLAB date to Excel serial date number
x2mdate(Not recommended; use datetime) Excel serial date number to MATLAB serial date number or datetime value

Orari in MATLAB

timezonesList all time zones
leapsecondsList all leap seconds supported by datetime data type (Da R2020a)
matlab.datetime.compatibility.convertDatenumConvert inputs to datetime values in a backward-compatible way (Da R2022a)

Argomenti

Risoluzione dei problemi

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.