欢迎来到天天文库
浏览记录
ID:35249237
大小:45.00 KB
页数:5页
时间:2019-03-22
《通用的日期格式与儒略日(julianday)格式的互相转换》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、通用的日期格式与儒略日(julianday)格式的互相转换李文军中国地震局地震预测研究所北京100036liwj@seis.ac.cn儒略日(Julianday)是指由公元前4713年1月1日,协调世界时中午12时开始所经过的天数,多为天文学家采用,用以作为天文学的单一历法,把不同历法的年表统一起来。儒略日是一种不用年月的长期纪日法,简写为JD。是由法国纪年学家史迦利日(JosephJustusScliger1540年-1609年)在1583年所创,这名称是为了纪念他的父亲——意大利学者JuliusCaesarS
2、caliger(1484年-1558年)。以儒略日计日是为方便计算年代相隔久远或不同历法的两事件所间隔的日数。为简化起见,在地震学中用到的Julian日期有时用来指这样的日期格式,即当前年份和当天位于这一年的第几天的结合。例如,2006年1月1日表示为2006001,而2008年12月31日表示为2008366。因此,该格式并不等同于Julian日历计算的日期,但是,可以极大地方便我们在地震学中的数据处理,在许多地震学数据格式中都用这种简化儒略日表示日期,如sac、seed、miniseed等格式。而在撰写论文的
3、图件中我们又希望恢复成普通的日期格式,因而通用格式和简化儒略日之间的转换是一个经常要做的事以下有两个程序,第一个是matlab编写的普通通用日期转换为上述简化儒略日(Julianday)的程序代码,第二个是同样用matlab编写的将儒略日转回普通日期格式的代码:1、普通通用日期转换为简化儒略日(Julianday)的程序代码functiony=julia(theyear,themonth,theday);%returnthejulianday(year,day)定义函数julia为转换为julian日期函数,变量
4、y为返回的julian日期,输入变量为theyear/年,themonth/月,theday/日leapyear=rem(theyear,4);%年对4求余数ifleapyear>0leap=0;%判断余数大于0,不能被4整除,则用leap标记这一年不是闰年(标记为0)elseifrem(theyear,100)==0&rem(theyear,400)~=0leap=0;%能被4整除但是不能被400整除也不是闰年,则用leap标记这一年不是闰年elseleap=1;%其他情况是闰年endend%%%%%%采用平年
5、的日历,按1-12月分月计算julian日期ifthemonth==1juliaday=theday;endifthemonth==2juliaday=theday+31;endifthemonth==3juliaday=theday+59;endifthemonth==4juliaday=theday+90;endifthemonth==5juliaday=theday+120;endifthemonth==6juliaday=theday+151;endifthemonth==7juliaday=theday
6、+181;endifthemonth==8juliaday=theday+212;endifthemonth==9juliaday=theday+243;endifthemonth==10juliaday=theday+273;endifthemonth==11juliaday=theday+304;endifthemonth==12juliaday=theday+334;endifleap==1ifthemonth<=2%如果是闰年,当月份小于2月时,julian日期与平年相同juliaday=juliaday
7、;endifthemonth>=3juliaday=juliaday+1;%当月份大于2月时,在平年的基础上加一天endendy(1)=theyear;y(2)=juliaday;%返回的矢量y,第一个元素为年,第二个元素为Julian日将儒略日转回普通日期格式的代码与上述代码类似2、儒略日(Julianday)转为普通日期格式的程序代码:functiony=rejulia(theyear,theday);%changejuliandaytonormalday(yearmonthday)leapyear=rem(
8、theyear,4);ifleapyear>0leap=0;elseifrem(theyear,100)==0&rem(theyear,400)~=0leap=0;elseleap=1;endendifleap==0iftheday<=31therealmonth=1;therealday=theday;endiftheday>=32&theday<=59therealm
此文档下载收益归作者所有