Universal Time to Local Time conversion

30 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Automotive 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by