Date conversion using GMT

조회 수: 4 (최근 30일)
John
John 2011년 12월 12일
I have a specific application in which I am reading in data into an array that includes a year (as an individual cell) and a GMT day. I need to convert the GMT day into an actual date using the year. If the year is in variable yr and GMT date in dGMT, I assumed that I could use the datestr function as follows:
d = datestr(addtodate(dGMT),floor(yr*365.25),'day'))
where datestr of the GMT returned the date in year 0000, and I simply add the amount of days that have elapsed since 1/1/0000. However, the data that is computed is off by about 2 weeks.
I did some investigating, and tried the above line of code with various years and dGMT=1.
I got the following: K>> datestr(addtodate((1),floor(1582*365.25),'day'))
ans =
31-Dec-1581
K>> datestr(addtodate((1),floor(1583*365.25),'day'))
ans =
10-Jan-1583
It seems that between year 1582 and 1583 10 days get added. Can anyone explain why, or possibly suggest another way to get the date?

답변 (1개)

Walter Roberson
Walter Roberson 2011년 12월 12일
There is actually good reason; see http://en.wikipedia.org/wiki/Gregorian_calendar

카테고리

Help CenterFile Exchange에서 Time Series Objects에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by