zoukankan      html  css  js  c++  java
  • 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是否要好些呢。

  • 相关阅读:
    青花瓷Java版
    让Broncho A1支持usbnet
    系统程序员成长计划组合的威力(三)
    【转】多CPU上的原子操作
    c#和javascript交互
    修改代码时有时会出现找不到某个组件
    UML用例建模的慨念和应用
    DJ曲二
    查询数据库里的存储过程的文本中的某个内容
    UML静态建模
  • 原文地址:https://www.cnblogs.com/westfly/p/2367515.html
Copyright © 2011-2022 走看看