char time: wrong label on years
조회 수: 3 (최근 30일)
이전 댓글 표시
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
답변 (2개)
dpb
2019년 12월 10일
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
Steven Lord
2019년 12월 10일
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
2019년 12월 10일
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...
참고 항목
카테고리
Help Center 및 File Exchange에서 Calendar에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!