Convert MATLAB datetime to POSIX time
p = posixtime( returns POSIX® times equivalent to the
datetime values in
t. The POSIX time is the number of seconds (including fractional seconds) elapsed
since 00:00:00 1-Jan-1970 UTC (Universal Coordinated Time), ignoring leap seconds.
p is a
If the time zone of
tis not specified, then
posixtimetreats the times in
tas UTC times. This interpretation might differ from your treatment of “unzoned”
datetimearrays in other contexts. For example, you might think of
datetime('now')as returning your local time. However,
posixtimeinterprets it as a UTC time.
If the time zone of
tis specified, then
posixtimeuses the offset for the time zone to compute POSIX times with respect to UTC.
The best practice is to specify the time zone of
Convert Datetime Array to POSIX Times
datetime values and convert them to the equivalent POSIX® times. Show the differences in POSIX times between zoned and unzoned
datetime values. The best practice is to specify a time zone for a
datetime array before calling
datetime array and specify its time zone.
t1 = datetime('2016-07-29 10:05:24') + calmonths(1:3); t1.TimeZone = 'America/New_York'
t1 = 1x3 datetime 29-Aug-2016 10:05:24 29-Sep-2016 10:05:24 29-Oct-2016 10:05:24
t1 to the equivalent POSIX times.
posixtime accounts for the time zone offset when it computes POSIX times.
format longG p1 = posixtime(t1)
p1 = 1×3 1.4725 1.4752 1.4777
datetime array with the same values as
t1, but with no time zone. Convert it to the equivalent POSIX times.
posixtime treats the times in
t2 as UTC times, with no time zone offset.
t2 = datetime('2016-07-29 10:05:24') + calmonths(1:3); p2 = posixtime(t2)
p2 = 1×3 1.4725 1.4751 1.4777
Show the differences between
p1. The differences are equal to the time offset, in seconds, between UTC and the time zone of
p2 - p1
ans = 1×3 -14400 -14400 -14400
Calculate with arrays that have more rows than fit in memory.
This function fully supports tall arrays. For more information, see Tall Arrays.
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Run code in the background using MATLAB®
backgroundPool or accelerate code with Parallel Computing Toolbox™
This function fully supports thread-based environments. For more information, see Run MATLAB Functions in Thread-Based Environment.
Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.
This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).