英文:
Vector of integer datetimes to matlab durations
问题
你可以将代表自Unix纪元以微秒为单位的整数向量转换为适用于时间表的Matlab持续时间:
microseconds = [1679909400000000; 1679909500000000; 1679909600000000];
durations = microseconds / 1e6; % 转换为秒
timetable = array2timetable(durations, 'RowTimes', datetime(durations, 'ConvertFrom', 'datenum'));
这会将整数向量转换为Matlab持续时间,然后将其用于时间表。
英文:
How do I convert a vector of integers that represent time in microseconds since the unix epoch into matlab durations suitable for use in timetables?
datetimes = [1679909400000000;1679909500000000;1679909600000000]
答案1
得分: 1
你可以在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
英文:
You can use ConvertFrom='posixtime'
in the datetime
constructor to do this, after dividing by 1e6
to get seconds from the POSIX epoch. You can get a datetime
representing the POSIX epoch by passing in the value 0.
>> 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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论