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是否要好些呢。

  • 相关阅读:
    BootStrap练习
    表单控件练习
    K近邻算法原理
    CSS 边框和颜色
    SVG平移和旋转
    SVG进阶练习
    SVG路标(marker)
    SVG 曲线与文字
    python函数与异常处理
    if-elif-else分支判断语句(附加continue和break)---举例说明
  • 原文地址:https://www.cnblogs.com/westfly/p/2367515.html
Copyright © 2011-2022 走看看