Midnight becomes noon with datetime function
Afficher commentaires plus anciens
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 commentaires
James Tursa
le 6 Août 2018
Modifié(e) : James Tursa
le 6 Août 2018
What does this show
which datetime
What version of MATLAB are you using?
Evan Dailey
le 6 Août 2018
Peter Meglis
le 6 Août 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
le 6 Août 2018
Modifié(e) : James Tursa
le 6 Août 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
le 6 Août 2018
Walter Roberson
le 7 Août 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.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Dates and Time dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!