Why doesn't timezone work with datetime
조회 수: 14 (최근 30일)
이전 댓글 표시
I want to convert a posix time to a datetime for the time zone at a specific longitude. The timezone function gives you the time zone at a specific longitude, but none of the outputs are accepted by datetime.
[a,b,c] = timezone(-80)
try
datetime(1685585049.879,'ConvertFrom','posixtime','TimeZone',a)
end
try
datetime(1685585049.879,'ConvertFrom','posixtime','TimeZone',b)
end
try
datetime(1685585049.879,'ConvertFrom','posixtime','TimeZone',c)
end
댓글 수: 0
채택된 답변
Star Strider
2023년 8월 24일
The timezone function is from the Mapping Toolbox, and its results are not compatible with the datetime function. The otherwise compatible timezones function does not take longitude arguments.
Try this instead —
TZ = string(fix(-80/15)) % Time Zone (-80° Longitude)
Time = datetime(1685585049.879,'ConvertFrom','posixtime','TimeZone',TZ)
.
댓글 수: 0
추가 답변 (1개)
Seth Furman
2023년 9월 14일
편집: Seth Furman
2023년 9월 14일
The value of TimeZone can be an ISO 8601 character vector of the form +HH:mm or -HH:mm; for example, '+01:00', to specify a time zone that is a fixed offset from UTC.
lon = 80;
zd = timezone(lon)
tz = compose("%+03d:00",zd)
dt = datetime(1685585049.879,ConvertFrom="posixtime",TimeZone=tz)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!