datetime

Methods

Method Reference: datetime.datetime

datetime: T = datetime ('now')
datetime: T = datetime ('today')
datetime: T = datetime ('tomorrow')
datetime: T = datetime ('yesterday')
datetime: T = datetime (DateStrings)
datetime: T = datetime (DateStrings, 'InputFormat', INFMT)
datetime: T = datetime (DateStrings,'InputFormat', INFMT, 'PivotYear', PIVOT)
datetime: T = datetime (DateVectors)
datetime: T = datetime (Y, MO, D)
datetime: T = datetime (Y, MO, D, H, MI, S)
datetime: T = datetime (Y, MO, D, H, MI, S, MS)
datetime: T = datetime (X, 'ConvertFrom', TYPE)
datetime: T = datetime (…, 'Format', FMT)
datetime: T = datetime (…, 'TimeZone', TZ)

Create a new array of datetime values.

T = datetime ('now') returns a scalar datetime array corresponding to the current date and time. T = datetime ('now') is the same as T = datetime (). Except for 'now', the same syntax can be used with 'today', 'tomorrow' and 'yesterday'. These options return the respective date but with time set at midnight.

T = datetime (DateStrings) creates a datetime array from the text in DateStrings representing points in time. In current implementation, DateStrings are parsed by Octave’s core datevec function, hence supported text formats are currently those supported by datevec.

T = datetime (DateStrings, 'InputFormat', INFMT) also allows to specify a particular input text format to parse DateStrings. It is always preferable to specify the format INFMT if it is known. Formats which do not specify a particular time component will have the value set to zero. Formats which do not a date will default to January 1st of the current year.

T = datetime (DateStrings, 'InputFormat', INFMT, 'PivotYear', PIVOT) also allows to specify a pivot year, which refers to the year at the start of the century to which two-digit years will be referenced. When not specified, it defaults to the current years minus 50.

T = datetime (DateVectors) creates a column vector of datetime values from the date vectors in DateVectors.

T = datetime (Y, MO, D creates an array of datetime values for corresponding elements of the Y, MO, and D arrays, which must be of the same size or scalars, must contain integer values, and they correspond to years, months, and days, respectively.

T = datetime (Y, MO, D, H, MI, S) also adds time components to the constructed datetime arrays. H, MI, and S must be of the same size or scalars. H and MI must contain integer values, whereas S may also contain a fractional part.

T = datetime (Y, MO, D, H, MI, S, MS) also adds a milliseconds component, MS, which may also have a fractional part.

T = datetime (X, 'ConvertFrom', TYPE) converts the numeric values in X to a datetime array according to the data type specified by TYPE. The following types are supported:

  • 'datenum'
  • 'excel'
  • 'posixtime'
  • 'epochtime'

T = datetime (…, 'Format', FMT) specifies the display format of the values in the output datetime array. Currently, only the default display format is implemented.

T = datetime (…, 'TimeZone', TZ) sets the time zone to the values in the output datetime array. If not specified, the computer’s local timezone is used. Supported time zones are specified in the IANA’s Time Zone Database. You may specify a new time zone by setting the 'TimeZone' property of the datetime array, in which case the new datetime values may include Daylight Saving Time (DST) in their computation.

See also: NaT, datetime, isdatetime, calendarDuration, duration

Source Code: datetime