如何将整数向量转换为自unix epoch以来以微秒为单位表示时间的matlab持续时间,适合在时间表中使用?
datetimes = [1679909400000000;1679909500000000;1679909600000000]
您可以在datetime
构造函数中使用ConvertFrom='posixtime'
来完成此操作,然后除以1e6
以获得POSIX纪元的秒数。您可以通过传入值0来获得代表POSIX纪元的datetime
。
>> timePoints = datetime(datetimes/1e6, ConvertFrom = 'posixtime')
timePoints =
3x1 datetime array
27-Mar-2023 09:30:00
27-Mar-2023 09:31:40
27-Mar-2023 09:33:20
>> timeSinceEpoch = timePoints - datetime(0, ConvertFrom = 'posixtime')
timeSinceEpoch =
3x1 duration array
466641:30:00
466641:31:40
466641:33:20