Universal Time to Local Time conversion

29 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Walter Roberson
Walter Roberson il 28 Mag 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.
  4 Commenti
root
root il 28 Mag 2023
This makes more sense and I am accepting your answer!
Thank you Walter!
Walter Roberson
Walter Roberson il 28 Mag 2023
Basically, "local time" turns out to be more political than geographic.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Automotive in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by