Midnight becomes noon with datetime function
이전 댓글 표시
I've run into a problem when converting date and time values to Matlab datetime values. The datetime function seems to force midnight (00:00) to noon (12:00). But, when comparing the outputs that look identical, Matlab says they are not. For example:
>> a = datetime(2016,03,01,0,0,0)
a =
datetime
2016 03 01 12 00 00
>> b = datetime(2016,03,01,12,0,0)
b =
datetime
2016 03 01 12 00 00
>> a == b
ans =
logical
0
How is this possible? Am I just missing something, or is there a good solution to correct or avoid this? This seems scary becaues if I'm using the output values in a larger script, how do I know that Matlab isn't confusing midnight and noon, and how would I be able to actually tell which is which?
댓글 수: 6
James Tursa
2018년 8월 6일
편집: James Tursa
2018년 8월 6일
What does this show
which datetime
What version of MATLAB are you using?
Evan Dailey
2018년 8월 6일
Peter Meglis
2018년 8월 6일
Evan,
What version of Matlab are you running? I just tried this on 2018a and got:
>> a = datetime(2016, 03, 01, 0, 0, 0)
a =
datetime
01-Mar-2016 00:00:00
James Tursa
2018년 8월 6일
편집: James Tursa
2018년 8월 6일
I can't reproduce your error on my PC. In fact, the format of the displayed results don't even match. My results:
>> a = datetime(2016,03,01,0,0,0)
a =
datetime
01-Mar-2016 00:00:00
>> which datetime
C:\Program Files\MATLAB\R2018a\toolbox\matlab\timefun\@datetime\datetime.m % datetime constructor
>> version
ans =
'9.4.0.813654 (R2018a)'
Mac or PC?
Evan Dailey
2018년 8월 6일
Walter Roberson
2018년 8월 7일
What is your system region set to? That could determine the default format for date representation. There is also a Preference about region that can affect the default format.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!