get epoch function in matlab in matlab

To get epoch time in MATLAB, you can use the posixtime function from the datetime class.

Here's an example:

main.m
epochTime = posixtime(datetime('now'))
39 chars
2 lines

This will return the current epoch time in seconds. You can convert it to milliseconds by multiplying it by 1000.

main.m
epochTimeInMilliseconds = epochTime * 1000
43 chars
2 lines

Alternatively, you can also use the posixtime function with a specific input time.

main.m
epochTime = posixtime(datetime('2022-01-01 00:00:00', 'TimeZone', 'UTC'))
74 chars
2 lines

In this case, the input time is January 1st, 2022 at 00:00:00 UTC.

related categories

gistlibby LogSnag