How to convert Universal time to Local time?

27 次查看(过去 30 天)
Dear All,
I am trying to convert Universal time to local time. I used this function
% Convert time values to datetime array
timeDatetime = datetime(selectedData(:,3)./3600, 'ConvertFrom', 'epochtime', 'Epoch', '1970-01-01');
% Apply time zone offset to datetime array
timeLocal = tzoffset(timeDatetime, 'EST','5');
but I got an error " Too Many input arguments".
Does anyone knows how to resoolve it?
Thank you,
Ara
  4 个评论
Steven Lord
Steven Lord 2022-12-27
dt = datetime('now', 'TimeZone', 'local')
dt = datetime
27-Dec-2022 14:55:52
dt.TimeZone
ans = '+00:00'
dt.TimeZone = 'America/New_York'
dt = datetime
27-Dec-2022 09:55:52
dt.TimeZone = 'local'
dt = datetime
27-Dec-2022 14:55:52
Ara
Ara 2022-12-28
Hi Steven,
Thank you for the code but I got thi error:
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.
Would you please tell me how to resolve it?

请先登录,再进行评论。

采纳的回答

Jan
Jan 2022-12-26
编辑:Jan 2022-12-26
The command tzoffset accepts one input only:
[dt,dst] = tzoffset(t)
Therefore the additional arguments 'EST','5' are not valid.
Maybe you mean
T = datetime(selectedData(:,3)./3600, ...
'ConvertFrom', 'epochtime', 'Epoch', '1970-01-01', 'TimeZone', 'UTC');
T.TimeZone = 'America/New_York'; % Set accordingly, perhaps 'system'
  3 个评论
Eric Sofen
Eric Sofen 2022-12-27
That looks like a problem with your conversion from epoch time, but without knowing the values of selectedData, it's hard to know what the appropriate conversion factor should be.
Ara
Ara 2022-12-28
Hi Eric,
Thank you for your comment.
Here is the selected data:
select = ~isMasked & selectElevation & selectPRN ;
selectedData = gpsData{stationId}.data(select,:) ;

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by