フィルターのクリア

how to shift datetime to account for daylight savings time

15 ビュー (過去 30 日間)
Kevin Johnson
Kevin Johnson 2022 年 3 月 24 日
コメント済み: Kevin Johnson 2022 年 3 月 25 日
The source data I am using expresses times in Coordinated Universal Time (UTC). I need to derive a MATLAB datetime array shifted correctly for daylight savings time throughout the year. It seems to me this ought to be straightforward, but I am finding this datetime business quite confusing. I simply want to shift times by one hour to account for DST. I am in the New York time zone.
If I put a datetime array into isdst, it does not return the correct answers (I get all logical zeros).
Thanks

採用された回答

Star Strider
Star Strider 2022 年 3 月 24 日
If you’ve not already explored it, the TimeZone property may be helpful.
Also see Specify Time Zones since it appears that ‘A different time zone offset is displayed depending on whether the datetime occurs during daylight saving time.’ according to the documentation.
  5 件のコメント
Peter Perkins
Peter Perkins 2022 年 3 月 24 日
Kevin, it looks like your retrieved_data.results is a cell array scalar structs containing POSIX times in their t field, in ms since 1970? Maybe? If round-off issues are a concern, you might consider using 'epochtime' and 'TicksPerSecond' instead of 'posixtime'.
In any case, if your code works for you, that's great. but there ought to be a way to vectorize this calculation down to something without loops, like maybe
results = [results{:}];
utc = [results.t];
dt = datetime(utc,'ConvertFrom','posixtime','TimeZone','America/New_York');
Kevin Johnson
Kevin Johnson 2022 年 3 月 25 日
Those are interesting ideas. I'll give them a try. Thanks!
Kevin

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by