char time: wrong label on years
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello,
I converted time from Gregorian days to classical label in dd/mm/yy in this way:
time_1= ncread ('/path/.nc', 'date_time');
time1=datestr(time_1,0);
but the label on YEARS is wrong, as you can see in the image. I have 0014, don't 2014!
Could you help me to have the right year?
thanks
example:
0 Kommentare
Antworten (2)
dpb
am 10 Dez. 2019
The problem is the explicit four-digit string for the year -- that overrides any pivot year input for either datenum/datestr as well as the recommended datetime.
You'll have to either fix up the input string or I'd recommend something like--
>> dtm=datetime('24-May-0014')
dtm =
datetime
24-May-0014
>> datetime(datevec(dtm)+[2000 0 0 0 0 0])
ans =
datetime
24-May-2014 00:00:00
>>
to fix up the year.
4 Kommentare
Steven Lord
am 10 Dez. 2019
There are a few situations where a duration and a calendarDuration are slightly different.
dt = datetime('3-Mar-1999')
dt1 = dt + years(1) % March 2nd 2000 5:49:12
dt2 = dt + calyears(1) % March 3rd 2000
years(1) is 365.2425 days. calyears(1) is exactly one calendar year, taking into account leap days.
dpb
am 10 Dez. 2019
Ah, yes. I knew something made me react to use the integer via datevec even though I didn't have a conscious connection to what, precisely. calyears() never came to mind; not yet totally assimilated the new(ish) datetime class and friends...
Siehe auch
Kategorien
Mehr zu Dates and Time finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!