Why does datetime return repeated values?

1 Ansicht (letzte 30 Tage)
MathWorks Support Team
MathWorks Support Team am 5 Sep. 2019
When I execute the following code snippet in MATLAB
start_time = datetime('05-Nov-2017 00:00:00','TimeZone','America/Los_Angeles');
end_time = datetime('05-Nov-2017 03:00:00','TimeZone','America/Los_Angeles');
DateString = start_time:1/2/24:end_time;
This ought to result in 7 times: 00:00, 00:30, 1:00, 1:30, 2:00, 2:30, and 3:00 on the same day.
Instead, it results in 9 times: 00:00, 00:30, 1:00, 1:30, 1:00, 1:30, 2:00, 2:30, and 3:00 on the same day.
If I do the same thing for the previous day, Nov 4, 2017, everything is fine...
start_time = datetime('04-Nov-2017 00:00:00','TimeZone','America/Los_Angeles');
end_time = datetime('04-Nov-2017 03:00:00','TimeZone','America/Los_Angeles');
DateString = start_time:1/24:end_time;
Gives 1 x 4 datetime array: 04-Nov-2017 00:00:00 04-Nov-2017 01:00:00 04-Nov-2017 02:00:00 04-Nov-2017 03:00:00
How can I explain this behavior?

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 5 Sep. 2019
This is due to Daylight Saving Time (DST).
In 2017, for the United States, Daylight Saving Time (DST) ended on Sunday, November 5. Clocks were set back 1 hour to standard time from 02:00 (2 am) to 01:00 (1 am), local time on this day.
This leads to the repeated values, which is the expected behavior.

Weitere Antworten (0)

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by