daylight.m

来自「航天工程工具箱」· M 代码 · 共 38 行

M
38
字号
function x=daylight(zone,isdls)
%DAYLIGHT  Daylight saving offset.
%   H = DAYLIGHT(ZONE,ISDLS)  where ZONE is the time zone:
%   ZONE<-3  : first sunday in april to last sunday in october (USA)
%   ZONE>=-3 : last sunday in mars to last sunday in ocober (Europe).
%   H is the hour which is added during daylight saving time.
%   If ISDLS = 0 then H = 0.
%
%   See also UTC, CALENDAR, DATENUM, CLOCK.

% Copyright (c) 2002-12-08, B. Rasmus Anthin.

time=clock;
Y=time(1);
M=time(2);
D=time(3);
h=time(4);
m=time(5);
s=time(6);
if zone<0
   M1=4;
else
   M1=3;
end
C1=calendar(Y,M1);
D1=C1(:,1);
if zone<-3
   D1=D1(min(find(D1)));
else
   D1=D1(max(find(D1)));
end
C2=calendar(Y,10);
D2=C2(:,1);
D2=D2(max(find(D2)));
dl.start=datenum(Y,M1,D1,2,0,0);
dl.end=datenum(Y,10,D2,3,0,0);
dl.now=datenum(Y,M,D,h,m,s);
x=(dl.start<dl.now) & (dl.now<dl.end) & isdls;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?