admin 管理员组

文章数量: 1087139


2024年1月24日发(作者:表示单个字符常量)

通用的日期格式与儒略日(julian day)格式的互相转换

李文军

中国地震局地震预测研究所 北京 100036 liwj@

儒略日(Julian day)是指由公元前4713年1月1日,协调世界时中午12时开始所经过的天数,多为天文学家采用,用以作为天文学的单一历法,把不同历法的年表统一起来。

儒略日是一种不用年月的长期纪日法,简写为JD。是由法国纪年学家史迦利日(Joseph Justus

Scliger 1540年-1609年)在1583年所创,这名称是为了纪念他的父亲——意大利学者Julius

Caesar Scaliger(1484年-1558年)。以儒略日计日是为方便计算年代相隔久远或不同历法的两事件所间隔的日数。

为简化起见,在地震学中用到的Julian 日期有时用来指这样的日期格式,即当前年份和当天位于这一年的第几天的结合。例如,2006 年 1 月 1 日表示为 2006001,而 2008 年

12 月 31 日表示为 2008366。因此,该格式并不等同于 Julian 日历计算的日期,但是,可以极大地方便我们在地震学中的数据处理,在许多地震学数据格式中都用这种简化儒略日表示日期,如sac、seed、miniseed等格式。而在撰写论文的图件中我们又希望恢复成普通的日期格式,因而通用格式和简化儒略日之间的转换是一个经常要做的事

以下有两个程序,第一个是matlab编写的普通通用日期转换为上述简化儒略日(Julian

day)的程序代码,第二个是同样用matlab编写的将儒略日转回普通日期格式的代码:

1、普通通用日期转换为简化儒略日(Julian day)的程序代码

function y=julia(theyear,themonth,theday);

%return the julian day (year,day)定义函数julia为转换为julian日期函数,变量y为返回的julian日期,输入变量为theyear/年,themonth/月,theday/日

leapyear=rem(theyear,4); %年对4求余数

if leapyear>0

leap=0; %判断余数大于0,不能被4整除,则用leap标记这一年不是闰年(标记为0)

else

if rem(theyear,100)==0 & rem(theyear,400)~=0

leap=0; %能被4整除但是不能被400整除也不是闰年,则用leap标记这一年不是闰年

else

leap=1; %其他情况是闰年

end

end

%%%%%%采用平年的日历,按1-12月分月计算julian日期

if themonth==1

juliaday=theday;

end

if themonth==2

juliaday=theday+31;

end

if themonth==3

juliaday=theday+59;

end

if themonth==4

juliaday=theday+90;

end

if themonth==5

juliaday=theday+120;

end

if themonth==6

juliaday=theday+151;

end

if themonth==7

juliaday=theday+181;

end

if themonth==8

juliaday=theday+212;

end

if themonth==9

juliaday=theday+243;

end

if themonth==10

juliaday=theday+273;

end

if themonth==11

juliaday=theday+304;

end

if themonth==12

juliaday=theday+334;

end

if leap==1

if themonth<=2 %如果是闰年,当月份小于2月时,julian日期与平年相同

juliaday=juliaday;

end

if themonth>=3

juliaday=juliaday+1; %当月份大于2月时,在平年的基础上加一天

end

end

y(1)=theyear;

y(2)=juliaday; %返回的矢量y,第一个元素为年,第二个元素为Julian日

将儒略日转回普通日期格式的代码与上述代码类似

2、儒略日(Julian day)转为普通日期格式的程序代码:

function y=rejulia(theyear,theday);%change julian day to normal day (year month day)

leapyear=rem(theyear,4);

if leapyear>0

leap=0;

else

if rem(theyear,100)==0 & rem(theyear,400)~=0

leap=0;

else

leap=1;

end

end

if leap==0

if theday<=31

therealmonth=1;

therealday=theday;

end

if theday>=32 & theday<=59

therealmonth=2;

therealday=theday-31;

end

if theday>=60 & theday<=90

therealmonth=3;

therealday=theday-59;

end

if theday>=91 & theday<=120

therealmonth=4;

therealday=theday-90;

end

if theday>=121 & theday<=151

therealmonth=5;

therealday=theday-120;

end

if theday>=152 & theday<=181

therealmonth=6;

therealday=theday-151;

end

if theday>=182 & theday<=212

therealmonth=7;

therealday=theday-181;

end

if theday>=213 & theday<=243

therealmonth=8;

therealday=theday-212;

end

if theday>=244 & theday<=273

therealmonth=9;

therealday=theday-243;

end

if theday>=274 & theday<=304

therealmonth=10;

therealday=theday-274;

end

if theday>=305 & theday<=334

therealmonth=11;

therealday=theday-305;

end

if theday>=335 & theday<=365

therealmonth=12;

therealday=theday-334;

end

end

if leap==1

if theday<=31

therealmonth=1;

therealday=theday;

end

if theday>=32 & theday<=60

therealmonth=2;

therealday=theday-31;

end

if theday>=61 & theday<=91;

therealmonth=3;

therealday=theday-60;

end

if theday>=92 & theday<=121;

therealmonth=4;

therealday=theday-91;

end

if theday>=122 & theday<=152;

therealmonth=5;

therealday=theday-121;

end

if theday>=153 & theday<=182;

therealmonth=6;

therealday=theday-152;

end

if theday>=183 & theday<=213;

therealmonth=7;

therealday=theday-182;

end

if theday>=214 & theday<=244;

therealmonth=8;

therealday=theday-213;

end

if theday>=245 & theday<=274;

therealmonth=9;

therealday=theday-244;

end

if theday>=275 & theday<=305;

therealmonth=10;

therealday=theday-275;

end

if theday>=306 & theday<=335;

therealmonth=11;

therealday=theday-306;

end

if theday>=336 & theday<=366;

therealmonth=12;

therealday=theday-335;

end

end

y(1)=theyear;

y(2)=therealmonth;

y(3)=therealday;

参考文献:

1、 /wiki/Julian_day 维基百科词条:儒略日(Julian day)

2、 /manuals/sac/ SAC Users Guide(v101.5c)- February 2012

3、 /manuals/ rdseed Manual(v5.2),2012.02.06


本文标签: 儒略 格式 简化 历法 转换