Datenum: how many seconds in a day?
古いコメントを表示
Datenum converts a date to a number representing the number of days past since a certain initial date. The documentation of datenum doesn't seem to say anything about this, but what is meant exactly by a day?
Is the day exactly 24h, i.e. 86400 (SI) seconds? Or is it a solar day?
If it is the former, how does it match with real life dates? By adding leap seconds? If so, a day is not (necessarily) exactly 86400 seconds; and how do I know when there are leap seconds and how many?
If it is the latter, how do I know how many (SI) seconds there were/are/will be in that day?
Thanks in advance
採用された回答
その他の回答 (4 件)
IF my guess is right matlab considers every day as 86400 seconds.. only in leap years does datenum make sure an extra day is added to the calendar in february..
a=datenum([2012,2,1,12,00,00]); % leap year feb
b=datenum([2012,3,1,12,00,00]);
b-a % leap year feb 29 days
c=datenum([2013,2,1,12,00,00]);
d=datenum([2013,3,1,12,00,00]);
d-c % no leap year feb 28 days
So the extra seconds are added on that day..
Star Strider
2014 年 3 月 7 日
1 投票
That question interested me enough to do a search. I can’t determine if MATLAB corrects for leap seconds and such (my guess is that MATLAB uses the SI day). The Astronomy & Astrophysics package for Matlab is the only site I found that might have what you want. It’s encyclopedic, so I just scanned it.
MATLAB tracks time only to the millisecond in its date and time functions, and day length variations seem to be significantly less than that. You probably have to do your own corrections to get variations in and different definitions of day length.
Sean de Wolski
2015 年 3 月 20 日
1 投票
It might be worth looking into the datetime class in R2014b. This allows you to account for leap seconds:
1 件のコメント
James Tursa
2015 年 3 月 20 日
I looked into this. See this link:
Peter Perkins
2015 年 3 月 22 日
Just to summarize and expand on what several people have said:
1) The datenum, datevec, and datestr functions work strictly in terms of 86400s days. Beyond what your system may or may not return when you use the now function, there is no accounting for leap seconds (they are treated as if they did not occur), and no time zone or daylight saving time support, although they do account for leap days. What those "seconds" mean is entirely up to your interpretation, those functions make no assumptions about solar days vs. SI days, or even about things like TT vs. TAI vs. GPS time. The interpretation becomes important when you want to convert between systems. And of course UTC does include leap seconds, so it's not continuous, although I suspect that most people wish that wasn't the case. At any rate, datenum, datevec, and datestr treat every day as 86400s long.
2) Since R2014b, MATLAB includes three new data types: datetime, duration, and calendarDuration. These allow you to opt in on support for time zones and daylight saving, and even for leap seconds. They also provide much higher precision, so Phillippe's example becomes
>> d = datetime('3-Sep-2014 17:00:00') - datetime('3-Sep-2014 16:00:00')
d =
01:00:00
>> minutes(d)
ans =
60
There is not yet support for GPS time or TAI in datetime. But again, in a continuous time system that ignores leap seconds (which is what you get by default with datetime), you can interpret the times however you want. It's only when converting to other systems that you have to be careful.
カテゴリ
ヘルプ センター および File Exchange で Dates and Time についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!