Universal Time to Local Time conversion

30 ビュー (過去 30 日間)
root
root 2023 年 5 月 28 日
コメント済み: Walter Roberson 2023 年 5 月 28 日
Hello
I have an array of univeral time in decimal hours.
I want to compute local time using this equation: LT = t1 + hours(loni/15); where t1 is univeral time and Loni is geographic longitude. But thereuslting LT values are from 00:00 to 12:00 only . I was expecting the usual range 00:00:00 to 23:59:59.
Any suggestions?
Thank you

採用された回答

Walter Roberson
Walter Roberson 2023 年 5 月 28 日
If LT is datetime() then you need to adjust the Format property of LT
I recently encountered someone who was doing a similar calculation to get some kind of solar magnetic time. In that case I showed that for accurate conversion for that purpose, you needed magnetic readings not just longitude / 15.
If you are not doing solar magnetic calculations, then the better way to convert is to use a datetime object with attached UTC time zone, and then set the TimeZone property of the object according to the time zone of the location. For example local time in Arizona is Mountain Standard Time all year, except within Navajo Nation, but other usa states with the same longitude observe Daylight Savings Time. Given an accurate time zone name, datetime can produce accurate local times including savings time adjustments that differ during the year.
Note: if you have a datetime object that has no TimeZone set and you set the time zone for it, then datetime will assume the time was the correct local time for that time zone. To have it adjust from UTC you must first set the time zone as UTC. Once there has been some time zone set for a datetime object, datetime will adjust the display as you change the time zone property.
  4 件のコメント
root
root 2023 年 5 月 28 日
This makes more sense and I am accepting your answer!
Thank you Walter!
Walter Roberson
Walter Roberson 2023 年 5 月 28 日
Basically, "local time" turns out to be more political than geographic.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAutomotive についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by