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!