Universal Time to Local Time conversion

10 views (last 30 days)
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

Accepted Answer

Walter Roberson
Walter Roberson on 28 May 2023
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.
Walter Roberson
Walter Roberson on 28 May 2023
Basically, "local time" turns out to be more political than geographic.

Sign in to comment.

More Answers (0)


Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!