Reputation: 1148
Is there an easy to use function in MATLAB to generate UNIX timestamps in millisecond precision. Somehow, in my search so far, I only come across human readable formats.
Upvotes: 1
Views: 860
Reputation: 17576
int32(posixtime(datetime()))
returns an integer number of seconds. You can, of course, multiply that by 1000 to get milliseconds, but I don't know how to read the clock to millisecond precision.
Documentation says posixtime
and datetime
were introduced in Matlab R2014b.
EDIT: Documentation says posixtime
includes fractional seconds. So I guess you can multiply it by 1000 and take the integer part to get milliseconds.
Upvotes: 1
Reputation:
instruction now
will return the number of days from Jan 0, 0000.
You can use the following formula to convert it to Unix time (note that I multiplied by 1000 to obtain the results in milliseconds instead of seconds).
int32(floor(60*60*24 * (datenum(now) - datenum('01-Jan-1970')))) * 1000
EDIT: I see that the returned value is not exactly the same as the one returned by http://www.unixtimestamp.com/
Returned value: 1471866676
From unixtimestamp: 1471859475
It differs by 116 minutes more o less. It might have something to do with leap seconds.
Upvotes: 3