Midnight becomes noon with datetime function
Mostrar comentarios más antiguos
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 comentarios
James Tursa
el 6 de Ag. de 2018
Editada: James Tursa
el 6 de Ag. de 2018
What does this show
which datetime
What version of MATLAB are you using?
Evan Dailey
el 6 de Ag. de 2018
Peter Meglis
el 6 de Ag. de 2018
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
el 6 de Ag. de 2018
Editada: James Tursa
el 6 de Ag. de 2018
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
el 6 de Ag. de 2018
Walter Roberson
el 7 de Ag. de 2018
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.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Dates and Time en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!