posixtime

Converts datetime values to POSIX (Unix) time in seconds.

Category: Language Fundamentals > Data Types

Syntax

p = posixtime(t)

Returns the seconds elapsed since 1970-01-01 00:00:00 UTC.

Description

POSIX time counts seconds from the Unix epoch, ignoring leap seconds. It is the common interchange format for timestamps in files, logs and web APIs. Fractions of a second are kept as fractions of the result.

The opposite conversion is datetime(p, 'ConvertFrom', 'posixtime').

Input arguments

t
Datetime array. If it has no time zone, it is taken as UTC.

Output arguments

p
Double array of the same size as t.

Example

posixtime(datetime(1970, 1, 2, 'TimeZone', 'UTC'))
datetime(86400, 'ConvertFrom', 'posixtime')
Output
ans = 86400
ans = datetime
   02-Jan-1970

See also

datetime datenum now juliandate