Incorrect datetime UTCLeapSeconds conversion
10 次查看(过去 30 天)
显示 更早的评论
I am working with leap second data, and as part of the calculations I did this for a particular leap second:
dt1 = datetime(1972,6,30,23,59,60,'TimeZone','UTCLeapSeconds')
dt2 = datetime(dt1,'TimeZone','UTCLeapSeconds')
dt2.TimeZone
dt1 - dt2
Well, you can see what happened. Even though the input and output time zones are both 'UTCLeapSeconds', the datetime( ) function has changed the time of this and jumped backwards 1 second. So to get around this I am forced to write code like this:
if( isequal(dt1.TimeZone,'UTCLeapSeconds') )
dt2 = dt1
else
dt2 = datetime(dt1,'TimeZone','UTCLeapSeconds')
end
dt1 - dt2
Looks like a bug to me, but does someone have another explanation for why this might be happening?
0 个评论
回答(1 个)
Cris LaPierre
2023-8-7
编辑:Cris LaPierre
2023-8-7
Potentially a bug, which you can report here: https://www.mathworks.com/support/contact_us.html
It looks like you have applied the time zone twice. You can do this instead:
dt1 = datetime(1972,6,30,23,59,60,'TimeZone','UTCLeapSeconds')
dt2 = dt1
dt2.TimeZone
dt1 - dt2
另请参阅
类别
在 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!