Main Content

NaT

Description

NaTis the representation for Not-a-Time, a value that can be stored in adatetimearray to indicate an unknown or missingdatetimevalue.

Thedatetimefunction creates aNaTvalue automatically when it cannot convert text to adatetimevalue, or for elements in adatetimearray where theYear,Month,Day,Hour,Minute, orSecondproperties are set toNaN. You also can assign the character vector,'NaT', to elements of an existingdatetimearray. Use theNaTfunction to create a newdatetimearray containing onlyNaTvalues.

example

NaT返回一个scalar Not-a-Time (NaT)datetimevalue.

t = NaT(n)返回一个nn-by-nmatrix ofNaTvalues.

t = NaT(sz1,...,szN)返回一个sz1-by-...-by-szNarray ofNaTvalues wheresz1,...,szNindicates the size of each dimension. For example,NaT(3,4)返回一个3-by-4 array ofNaTvalues.

t = NaT(sz)返回一个n array ofNaTvalues where the size vector,sz, definessize(t). For example,NaT([3,4])返回一个3-by-4 array ofNaTvalues.

example

t = NaT(___,'Format',fmt)返回一个datetimearray with the specified display format. Use this syntax to initialize adatetimearray. Not-a-Time values always display asNaT, but non-NaTvalues assigned to the array will display using the specified format.

t = NaT(___,'TimeZone',tz)返回一个n array ofNaTvalues in the time zone specified bytz.

Examples

collapse all

Create a 3-by-3 matrix ofNaTvalues.

t = NaT(3)
t =3x3 datetimeNaT NaT NaT NaT NaT NaT NaT NaT NaT

Create a 2-by-3 array ofNaTvalues and specify a date format.

t = NaT(2,3,'Format','dd/MM/yyyy')
t =2x3 datetimeNaT NaT NaT NaT NaT NaT

Assign adatetimevalue to an element oft.

t(1,2) = datetime('today')
t =2x3 datetimeNaT 26/11/2022 NaT NaT NaT NaT

Input Arguments

collapse all

Size of square matrix, specified as an integer.

  • Ifnis0, thentis an empty matrix.

  • Ifnis negative, then it is treated as0.

Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64

Size of each dimension, specified as separate arguments of integer values.

  • If the size of any dimension is0, thentis an empty array.

  • If the size of any dimension is negative, then it is treated as0.

Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64

每个维度的大小,指定为一个行向量of integer values. Each element of this vector indicates the size of the corresponding dimension:

  • If the size of any dimension is0, thentis an empty array.

  • If the size of any dimension is negative, then it is treated as0.

Example:sz = [2,3,4]creates a 2-by-3-by-4 array.

Data Types:single|double|int8|int16|int32|int64|uint8|uint16|uint32|uint64

Date format, specified as a character vector or string scalar. Use the lettersA-Zanda-zto define the format. For a complete list of valid letter identifiers, see theFormatproperty for datetime arrays.

Alternatively, use one of the following character vectors to specify a default format.

Value offmt Description

'default'

Use the default display format.

'defaultdate'

Use the default display format for datetime values created without time components.

Example:'yyyy MMM dd'

Data Types:char|string

Time zone region, specified as a character vector or string scalar.

The value oftzcan be:

  • '', to create an “unzoned”datetimearray that does not belong to a specific time zone.

  • The name of a time zone region from the IANA Time Zone Database, for example,'America/Los_Angeles'. The name of a time zone region accounts for the current and historical rules for standard and daylight offsets from UTC that are observed in a geographic region.

  • An ISO 8601 character vector of the form+HH:mmor-HH:mm, for example,'+01:00', to specify a time zone that is a fixed offset from UTC.

  • 'UTC', to create adatetimearray in Coordinated Universal Time.

  • 'UTCLeapSeconds', to create adatetimearray in Coordinated Universal Time that accounts for leap seconds. For the list of leap seconds supported by thedatetimedata type, seeleapseconds.

  • 'local', to create adatetimearray in the system time zone.

This table lists some common names of time zone regions from the IANA Time Zone Database.

Value ofTimeZone UTC Offset UTC DST Offset
'Africa/Johannesburg' +02:00 +02:00
'America/Chicago' −06:00 −05:00
'America/Denver' −07:00 −06:00
'America/Los_Angeles' −08:00 −07:00
'America/New_York' −05:00 −04:00
“美国/ Sao_Paulo” −03:00 −02:00
'Asia/Hong_Kong' +08:00 +08:00
'Asia/Kolkata' +05:30 +05:30
'Asia/Tokyo' +09:00 +09:00
'Australia/Sydney' +10:00 +11:00
'Europe/London' +00:00 +01:00
'Europe/Zurich' +01:00 +02:00

Data Types:char|string

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2015b