La traduction de cette page n'est pas à jour. Cliquez ici pour voir la dernière version en anglais.
Dates et heures
Les types de données de date et d’heure datetime
, duration
et calendarDuration
permettent le calcul, la comparaison et l’affichage formaté efficaces des dates et des heures. Ces tableaux s’utilisent de la même manière que les tableaux numériques. Vous pouvez ajouter, soustraire, trier, comparer, concaténer et représenter graphiquement des valeurs de date et d’heure. Vous pouvez également représenter des dates et des heures sous forme de tableaux numériques ou de texte. Pour plus d’informations, consultez Represent Dates and Times in MATLAB ou regardez la vidéo Date and Time Arrays (Tableaux de dates et d’heures).
Fonctions
Rubriques
- 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. - Compare Dates and Time
Compare dates, times, and durations by using relational operators, such as
>
,<
, and==
, taking time zones and daylight saving time into account. - Set Date and Time Display Format
The
Format
property ondatetime
,duration
, andcalendarDuration
arrays controls the display of values in each array. You can change the value of this property. Changing theFormat
property does not change the values in the array, only their display. - Specify Time Zones
Specify time zones for
datetime
arrays to account for time zone offsets, daylight saving time, or leap seconds. - 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.
Résolution des problèmes
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.