|
在 Python 中,datetime.fromtimestamp(timestamp / 1000) 默认使用本地时区来生成时间。而在 MATLAB 中,datetime(timestamp / 1000, 'ConvertFrom', 'posixtime')默认生成 UTC 时间。
如果时间戳是 UTC 时间,而我们希望在 MATLAB 中将其转换为本地时间,可以使用 MATLAB 的时区功能来调整时间。以下是如何在 MATLAB 中将 UTC 时间转换为本地时间的示例:- % 假设 timestamp 是时间戳
- timestamp_str = datestr(datetime(timestamp / 1000, 'ConvertFrom', 'posixtime', 'TimeZone', 'UTC'), 'yyyy-mm-dd HH:MM:SS');
- % 将时间转换为本地时区
- local_time = datetime(timestamp / 1000, 'ConvertFrom', 'posixtime', 'TimeZone', 'local');
- timestamp_str = datestr(local_time, 'yyyy-mm-dd HH:MM:SS');
复制代码
|
|