Julian Day

从项目webalizer抓取到一个有用的关于儒略日(Julian Day)的函数。

关于"儒略日数"介绍参考

http://blog.sina.com.cn/s/blog_53027c620100mtii.html

 

/*****************************************************************/
/**/
/* JDATE - Julian date calculator */
/**/
/* Calculates the number of days since Jan 1, 0000. */
/**/
/* Originally written by Bradford L. Barrett (03/17/1988) */
/* Returns an unsigned long value representing the number of */
/* days since January 1, 0000. */
/**/
/* Note: Due to the changes made by Pope Gregory XIII in the */
/* 16th Centyry (Feb 24, 1582), dates before 1583 will */
/* not return a truely accurate number (will be at least */
/* 10 days off). Somehow, I don't think this will */
/* present much of a problem for most situations :) */
/**/
/* Usage: days = jdate(day, month, year) */
/**/
/* The number returned is adjusted by 5 to facilitate day of */
/* week calculations. The mod of the returned value gives the */
/* day of the week the date is. (ie: dow = days % 7 ) where */
/* dow will return 0=Sunday, 1=Monday, 2=Tuesday, etc... */
/**/
/*****************************************************************/

u_int64_t jdate( int day, int month, int year )
{
u_int64_t days; /* value returned */
int mtable[] = {0,31,59,90,120,151,181,212,243,273,304,334};

/* First, calculate base number including leap and Centenial year stuff */

days=(((u_int64_t)year*365)+day+mtable[month-1]+
((year+4)/4) - ((year/100)-(year/400)));

/* now adjust for leap year before March 1st */

if ((year % 4 == 0) && !((year % 100 == 0) &&
(year % 400 != 0)) && (month < 3))
--days;

/* done, return with calculated value */

return(days+5);
}


如果调用得多的话,数组mtable声明为static是否要好些呢。

 

 

 

转载于:https://www.cnblogs.com/westfly/archive/2012/02/25/2367515.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值