2 qq 15290009 qq_15290009 于 2016.03.04 16:10 提问

js求大神们看看能不能把2015变成这样的二O一五

图片说明

改成图片上的那种样式 代码贴在楼下了

还有就是 吧js单独拿出来遇见这个问题
图片说明

怎么解决

5个回答

showbo
showbo   Ds   Rxr 2016.03.04 21:56
已采纳

生成option显示的Neri直接转为汉字的数字就好了,农历的年的月份就用汉字的年份

 <script>
    function toCNNumber(v) {
        var r = '', cn = 'O一二三四五六七八九十';
        v = v.toString();
        for (var i = 0; i < v.length; i++) r += cn.charAt(v.charAt(i));
        return r;
    }
    var now = new Date(), y = now.getFullYear(), ba = 20/*取和当前时间相差前后20年*/;
    var yOpts = '',cnyOpts='', mOpts = '', dOpts = '';
    for (var i = y - 20, j = y + 20; i <= j; i++) {
        cnyOpts += '<option value="' + i + '">' + toCNNumber(i) + '</option>';//汉字的年份
        yOpts += '<option value="' + i + '">' + i + '</option>';
    }
    for (var i = 1, j = 12; i <= j; i++) mOpts += '<option value="' + i + '">' + i + '</option>';
    for (var i = 1, j = 31; i <= j; i++) dOpts += '<option value="' + i + '">' + i + '</option>';
</script>

<select id="lstY">
<script>document.write(cnyOpts)</script></select>年
<select id="letY">
<script>document.write(cnyOpts)</script></select>年
qq_15290009
qq_15290009 好的 我明天研究看看 不行再找你 这就天咋没看见你呢?
接近 2 年之前 回复
rui888
rui888   Ds   Rxr 2016.03.04 16:51

你这个得重写你的日期控件吧 http://www.w2bc.com/demo/2015-02-27-jquery-date/index.html

比较难。

qq_15290009
qq_15290009 你帮我看一下 还有 出现哪的个问题 怎么解决
接近 2 年之前 回复
qq_15290009
qq_15290009 不晓得 我这个也是在网上 抄 你能帮我谢谢吗 我吧日期控件贴上来
接近 2 年之前 回复
qq_15290009
qq_15290009   2016.03.04 17:01

<!DOCTYPE html>
<html>
<head>
<title>计算宝之日期计算网页版</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" charset="utf-8">    
<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
<meta name="keywords" content="Bootstrap Responsive Templates, Iphone Compatible Templates, Smartphone Compatible Templates, Ipad Compatible Templates, Flat Responsive Templates"/>
<script src="js/jquery-1.11.0.min.js"></script>
<script src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/year_month_day.js"></script>
<link href="css/dataCompete.css" rel="stylesheet" type="text/css"/>
<link href="css/bootstrap.css" rel='stylesheet' type='text/css' />
<link href="css/style.css" rel='stylesheet' type='text/css' />
<script>
    var now = new Date(), y = now.getFullYear(), ba = 20/*取和当前时间相差前后20年*/;
    var yOpts = '', mOpts = '', dOpts = '';
    for (var i = y - 20, j = y + 20; i <= j; i++) yOpts += '<option value="' + i + '">' + i + '</option>';
    for (var i = 1, j = 12; i <= j; i++) mOpts += '<option value="' + i + '">' + i + '</option>';
    for (var i = 1, j = 31; i <= j; i++) dOpts += '<option value="' + i + '">' + i + '</option>';
</script>

</head>
<body>
    <!--start-header-->
            <div id="home" class="header">
                    <div class="header-top">
                        <div class="header">
                            <a href="index.html"><img src="images/logo.png" alt=""></a>
                        </div>
                        <div class="header-nav">
                            <ul>
                                <li><a href="#">首页</a></li>    
                                <li><a href="compete.html" class="active">装修计算</a></li>
                                <li><a href="dataCompete.html">时间计算</a></li>     
                                <li><a href="#">服装计算</a></li>
                            </ul>
                        </div>
                    </div>
        </div>
   <!--End-header-->

            <div class="maincontent">
                        <h2>在线日期计算</h2>

                            <script>//显示当前日期时间
                                setInterval("jnkc.innerHTML=new Date().toLocaleString()+'星期'+'日一二三四五六'.charAt(new Date().getDay());",1000);
                            </script>


                            <div id="t1">

                                <p class="today">今天是</p><label id="jnkc" ></label> 
                                <div class="sj" ><span class="qz">起止</span><span class="jz">截止</span></div>
                                <table border="0" >
                                <tr><td id="tdNow" colspan="2"></tr>
                                <tr>
                                <td align = "center">
                                <select id="stY"><script>document.write(yOpts)</script></select>年
                                <select id="stM"><script>document.write(mOpts)</script></select>月
                                <select id="stD"><script>document.write(dOpts)</script></select>日<br /><br />
                                <select id="lstY"><script>document.write(yOpts)</script></select>年
                                <select id="lstM"><script>document.write(mOpts)</script></select>月
                                <select id="lstD"><script>document.write(dOpts)</script></select>日
                                </td>
                                <td align = "center">
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <select id="etY"><script>document.write(yOpts)</script></select>年
                                <select id="etM"><script>document.write(mOpts)</script></select>月
                                <select id="etD"><script>document.write(dOpts)</script></select>日<br /><br />
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <select id="letY"><script>document.write(yOpts)</script></select>年
                                <select id="letM"><script>document.write(mOpts)</script></select>月
                                <select id="letD"><script>document.write(dOpts)</script></select>日
                                </td>
                                </tr>
                                </table>
                                <br>
                                <table>
                                <tr><td colspan="2" align="center">距离截止日期:<span id="sRsty" ></span>&nbsp;
                                                        <span id="sRstm"></span>&nbsp;
                                                        <span id="sRstw"></span>&nbsp;
                                                        <span id="sRstd"></span>&nbsp;


                                                        <span id="sRsth" ></span>&nbsp;
                                                        <span id="sRsti" ></span>&nbsp;
                                                        <span id="sRsts" ></span>

                                </td></tr>
                                </table>

                            </div>




           </div>

        <script>
    var stY = document.getElementById('stY'), stM = document.getElementById('stM'), stD = document.getElementById('stD'),
        lstY = document.getElementById('lstY'), lstM = document.getElementById('lstM'), lstD = document.getElementById('lstD'),
        etY = document.getElementById('etY'), etM = document.getElementById('etM'), etD = document.getElementById('etD'),
        letY = document.getElementById('letY'), letM = document.getElementById('letM'), letD = document.getElementById('letD');
    var lMons = '正二三四五六七八九十冬腊', lDays1 = '初十廿卅', lDays2 = '一二三四五六七八九十', v,ds;
    //更新农历月份显示
    for (var i = 0; i < 12; i++) {
        v = parseInt(lstM.options[i].value) - 1;
        lstM.options[i].text = letM.options[i].text = lMons.charAt(v) + '月';
    }
    //更新农历月份显示
    for (var i = 0; i < 31; i++) {
        v = parseInt(lstD.options[i].value);
        if (v <= 10) ds = lDays1.charAt(0);
        else ds = lDays1.charAt(parseInt(v.toString().charAt(0)));
        lstD.options[i].text = letD.options[i].text = ds + lDays2.charAt((v - 1) % 10);
    }
    //下拉框更改事件,更新对应的农历新历日期
    stY.onchange = stM.onchange = stD.onchange = lstY.onchange = lstM.onchange = lstD.onchange = 
    etY.onchange = etM.onchange = etD.onchange = letY.onchange = letM.onchange = letD.onchange = function () {
        var sign = this.id.indexOf('l') == 0;//是否农历日期框变化
        var idPrefix = /[a-z]+/.exec(this.id)[0];//获取起始或者截止前缀
        var dateStr = window[idPrefix + 'Y'].value + '/' + window[idPrefix + 'M'].value + '/' + window[idPrefix + 'D'].value;
        var date = new Date(dateStr);//生成日期对象,注意这里,如果日期选择错误,js会自动更正为最新日期,如2015/2/31,会变为2015/3/3
        //////////////
        if ((date.getFullYear() + '/' + (date.getMonth() + 1) + '/' + date.getDate()) != dateStr) {//和源字符不一样说明日期选错,重置select为新生成日期或者自己修改这里alert提示错误return返回也行
            window[idPrefix + 'Y'].value = date.getFullYear();
            window[idPrefix + 'M'].value = date.getMonth() + 1;
            window[idPrefix + 'D'].value = date.getDate();
        }
        /////////////
        var rstDate = CalConvert(date, !sign, true);//执行农历新历转换
        if (rstDate) {//转换成功,更新对应的农历或者新历下拉框
            if (sign) idPrefix = idPrefix.replace('l', '');
            else idPrefix = 'l' + idPrefix;
            window[idPrefix + 'Y'].value = rstDate.getFullYear();
            window[idPrefix + 'M'].value = rstDate.getMonth() + 1;
            window[idPrefix + 'D'].value = rstDate.getDate();
        }
        //计算时间差
        var stDate = new Date(stY.value + '/' + stM.value + '/' + stD.value);
        var etDate = new Date(etY.value + '/' + etM.value + '/' + etD.value);
        var s = Math.abs(etDate.getTime() - stDate.getTime()) ;//总秒数
        var y = Math.floor(s / (365*24*3600*1000));//多少年 
        var m = Math.floor(s / (31*24*3600*1000));//多少月
        var w = Math.floor(s / (7*24*3600*1000));//多少周
        var d = Math.floor(s / (24*3600*1000));//多少天
        var h = Math.floor(s / (3600*1000));//多少小时
        var i = Math.floor(s / (60*1000));//多少分钟
        var s = Math.floor(s / 1000);//多少秒
        document.getElementById('sRsty').innerHTML = y + '年' ;
        document.getElementById('sRstm').innerHTML = m + '月' ;
        document.getElementById('sRstw').innerHTML = w + '周' ;
        document.getElementById('sRstd').innerHTML = d + '天' ;
        document.getElementById('sRsth').innerHTML = h + '小时';
        document.getElementById('sRsti').innerHTML = i + '分钟' ;
        document.getElementById('sRsts').innerHTML = s + '秒';
    }
    //设置新历为当前日期
    stY.value = etY.value = y;
    stM.value = etM.value = now.getMonth() + 1;
    stD.value = etD.value = now.getDate();
    //触发onchange事件设置对应农历日期
    stD.onchange();
    etD.onchange();

</script> 


        <!--footer-->        

        <div class="contact">
            <div class="container">
                <div class="contact-main">
                    <div class="col-md-4 contact-left">
                        <h4>联系我们</h4>
                        <p><span>邮箱:</span><a href="mailto:@example.com">dream is land@163.com</a></p>
                        <p><span>电话:</span>张剑:18311030677</p>
                    </div>
                    <div class="col-md-4 contact-left">
                        <h4>地址:</h4>
                        <p>北京市石景山区玉泉路11号安格写字楼611室</p>
                    </div>
                    <!--<div class="col-md-4 contact-left">
                        <h4>友情链接:</h4>
                        <ul>
                            <li> <a href="http://openapi.qzone.qq.com/oauth/show?which=Login&display=pc&response_type=code&client_id=208157&redirect_uri=http%3A%2F%2Fhome.meishichina.com%2Fapp%2Fqq%2Fcallback.php&state=e47b1cdee9b0a4138cfb44749cd85ed5"><span class="twitter"> </span></a>

                                 </li>
                            <li>  <a href="http://t.qq.com/"><span class="googleplus"> </span></a></li>
                            <li><a href="https://wx.qq.com/"><span class="pinterest"> </span></a></li>

                        </ul>
                    </div>-->
                    <div class="clearfix"> </div>
                </div>
            </div>
            <a href="#home" id="toTop" class="scroll" style="display: block;"> <span id="toTopHover" style="opacity: 1;"> </span></a>
        </div>



</body>
</html>
qq_15290009
qq_15290009   2016.03.04 17:02
 // JavaScript阳历,阴历相互转换源代码
// @date   2010-06-01
function tagLunarCal(d, i, w, k, m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13) {
    this.BaseDays = d;         /* 1 月 1 日到正月初一的累计日 */
    this.Intercalation = i;    /* 闰月月份. 0==此年沒有闰月 */
    this.BaseWeekday = w;      /* 此年 1 月 1 日为星期减 1 */
    this.BaseKanChih = k;      /* 此年 1 月 1 日之干支序号减 1 */
    this.MonthDays = [m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13]; /* 此农历年每月之大小, 0==小月(29日), 1==大月(30日) */
}
// 闰年判断.返回1 或 0
function GetLeap(year) {
    return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)) ? 1 : 0;
}
// 主类入口
// @param {Date} new Date(y,m,d)
// @param {Boolean} false: 农历-->公历 true: 公历 --> 农历,默认false
// @returnDate {Boolean} false: 返回字符串 true: 返回Date对象,默认false
// @return {String} 见example
// @example
// CalConvert(new Date(2010,3,19), false) 即农历的四月十九转为公历  结果为 2010-06-01
// CalConvert(new Date(2010,5,1), true)   即公历的6月1日转为农历    结果为 2010年四月十九
//
function CalConvert(date, sign,returnDate) {
    // 日期上下限
    FIRSTYEAR = 1936;
    LASTYEAR = 2031;
    // 返回结果值
    RESULT = 0;
    // 对照表
    LunarCal = [
        new tagLunarCal(23, 3, 2, 17, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0), /* 1936 */
        new tagLunarCal(41, 0, 4, 23, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1),
        new tagLunarCal(30, 7, 5, 28, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1),
        new tagLunarCal(49, 0, 6, 33, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1),
        new tagLunarCal(38, 0, 0, 38, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1), /* 1940 */
        new tagLunarCal(26, 6, 2, 44, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0),
        new tagLunarCal(45, 0, 3, 49, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0),
        new tagLunarCal(35, 0, 4, 54, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1),
        new tagLunarCal(24, 4, 5, 59, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1), /* 1944 */
        new tagLunarCal(43, 0, 0, 5, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1),
        new tagLunarCal(32, 0, 1, 10, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1),
        new tagLunarCal(21, 2, 2, 15, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1),
        new tagLunarCal(40, 0, 3, 20, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1), /* 1948 */
        new tagLunarCal(28, 7, 5, 26, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1),
        new tagLunarCal(47, 0, 6, 31, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1),
        new tagLunarCal(36, 0, 0, 36, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0),
        new tagLunarCal(26, 5, 1, 41, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1), /* 1952 */
        new tagLunarCal(44, 0, 3, 47, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1),
        new tagLunarCal(33, 0, 4, 52, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0),
        new tagLunarCal(23, 3, 5, 57, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1),
        new tagLunarCal(42, 0, 6, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1), /* 1956 */
        new tagLunarCal(30, 8, 1, 8, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0),
        new tagLunarCal(48, 0, 2, 13, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0),
        new tagLunarCal(38, 0, 3, 18, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1),
        new tagLunarCal(27, 6, 4, 23, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0), /* 1960 */
        new tagLunarCal(45, 0, 6, 29, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0),
        new tagLunarCal(35, 0, 0, 34, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1),
        new tagLunarCal(24, 4, 1, 39, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0),
        new tagLunarCal(43, 0, 2, 44, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0), /* 1964 */
        new tagLunarCal(32, 0, 4, 50, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1),
        new tagLunarCal(20, 3, 5, 55, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0),
        new tagLunarCal(39, 0, 6, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0),
        new tagLunarCal(29, 7, 0, 5, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1), /* 1968 */
        new tagLunarCal(47, 0, 2, 11, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1),
        new tagLunarCal(36, 0, 3, 16, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0),
        new tagLunarCal(26, 5, 4, 21, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1),
        new tagLunarCal(45, 0, 5, 26, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1), /* 1972 */
        new tagLunarCal(33, 0, 0, 32, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1),
        new tagLunarCal(22, 4, 1, 37, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1),
        new tagLunarCal(41, 0, 2, 42, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1),
        new tagLunarCal(30, 8, 3, 47, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1), /* 1976 */
        new tagLunarCal(48, 0, 5, 53, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1),
        new tagLunarCal(37, 0, 6, 58, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1),
        new tagLunarCal(27, 6, 0, 3, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0),
        new tagLunarCal(46, 0, 1, 8, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0), /* 1980 */
        new tagLunarCal(35, 0, 3, 14, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1),
        new tagLunarCal(24, 4, 4, 19, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1),
        new tagLunarCal(43, 0, 5, 24, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1),
        new tagLunarCal(32, 10, 6, 29, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1), /* 1984 */
        new tagLunarCal(50, 0, 1, 35, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0),
        new tagLunarCal(39, 0, 2, 40, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1),
        new tagLunarCal(28, 6, 3, 45, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0),
        new tagLunarCal(47, 0, 4, 50, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1), /* 1988 */
        new tagLunarCal(36, 0, 6, 56, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0),
        new tagLunarCal(26, 5, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1),
        new tagLunarCal(45, 0, 1, 6, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0),
        new tagLunarCal(34, 0, 2, 11, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0), /* 1992 */
        new tagLunarCal(22, 3, 4, 17, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0),
        new tagLunarCal(40, 0, 5, 22, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0),
        new tagLunarCal(30, 8, 6, 27, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1),
        new tagLunarCal(49, 0, 0, 32, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1), /* 1996 */
        new tagLunarCal(37, 0, 2, 38, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1),
        new tagLunarCal(27, 5, 3, 43, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1),
        new tagLunarCal(46, 0, 4, 48, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1), /* 1999 */
        new tagLunarCal(35, 0, 5, 53, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1), /* 2000 */
        new tagLunarCal(23, 4, 0, 59, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1),
        new tagLunarCal(42, 0, 1, 4, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1),
        new tagLunarCal(31, 0, 2, 9, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0),
        new tagLunarCal(21, 2, 3, 14, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1), /* 2004 */
        new tagLunarCal(39, 0, 5, 20, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1),
        new tagLunarCal(28, 7, 6, 25, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1),
        new tagLunarCal(48, 0, 0, 30, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1),
        new tagLunarCal(37, 0, 1, 35, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1), /* 2008 */
        new tagLunarCal(25, 5, 3, 41, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1),
        new tagLunarCal(44, 0, 4, 46, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1),
        new tagLunarCal(33, 0, 5, 51, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1),
        new tagLunarCal(22, 4, 6, 56, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0), /* 2012 */
        new tagLunarCal(40, 0, 1, 2, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0),
        new tagLunarCal(30, 9, 2, 7, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1),
        new tagLunarCal(49, 0, 3, 12, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1),
        new tagLunarCal(38, 0, 4, 17, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0), /* 2016 */
        new tagLunarCal(27, 6, 6, 23, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1),
        new tagLunarCal(46, 0, 0, 28, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0),
        new tagLunarCal(35, 0, 1, 33, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0),
        new tagLunarCal(24, 4, 2, 38, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1), /* 2020 */
        new tagLunarCal(42, 0, 4, 44, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1),
        new tagLunarCal(31, 0, 5, 49, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0),
        new tagLunarCal(21, 2, 6, 54, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1),
        new tagLunarCal(40, 0, 0, 59, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1), /* 2024 */
        new tagLunarCal(28, 6, 2, 5, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0),
        new tagLunarCal(47, 0, 3, 10, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1),
        new tagLunarCal(36, 0, 4, 15, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1),
        new tagLunarCal(25, 5, 5, 20, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0), /* 2028 */
        new tagLunarCal(43, 0, 0, 26, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1),
        new tagLunarCal(32, 0, 1, 31, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0),
        new tagLunarCal(22, 3, 2, 36, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0)];
    /* 西曆年每月之日數 */
    SolarCal = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
    /* 西曆年每月之累積日數, 平年與閏年 */
    SolarDays = [
        0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365, 396,
        0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366, 397];
    AnimalIdx = ["馬 ", "羊 ", "猴 ", "雞 ", "狗 ", "豬 ", "鼠 ", "牛 ", "虎 ", "兔 ", "龍 ", "蛇 "];
    LocationIdx = ["南", "東", "北", "西"];
    var func = sign ? function (d) {
        function getBit(m, n) { return (m >> n) & 1; }
        var mons = "正二三四五六七八九十冬腊", Cal = [0x41A95, 0xD4A, 0xDA5, 0x20B55, 0x56A, 0x7155B, 0x25D, 0x92D, 0x5192B, 0xA95, 0xB4A, 0x416AA, 0xAD5, 0x90AB5, 0x4BA, 0xA5B, 0x60A57, 0x52B, 0xA93, 0x40E95];
        var total, m, n, k, isEnd = false, t = d.getYear();
        if (t < 1900) t += 1900;
        total = (t - 2001) * 365 + Math.floor((t - 2001) / 4) + [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334][d.getMonth()] + d.getDate() - 23;
        if (d.getYear() % 4 == 0 && d.getMonth() > 1) total++;
        for (m = 0; m < 1000; m++) {
            k = (Cal[m] < 0xfff) ? 11 : 12;
            for (n = k; n >= 0; n--) {
                if (total <= 29 + getBit(Cal[m], n)) {
                    isEnd = true;
                    break;
                }
                total = total - 29 - getBit(Cal[m], n);
            }
            if (isEnd) break;
        }
        var cYear = 2001 + m, cMonth = k - n + 1;
        if (k == 12) {
            if (cMonth == Math.floor(Cal[m] / 0x10000) + 1)
                cMonth = 1 - cMonth;
            if (cMonth > Math.floor(Cal[m] / 0x10000) + 1)
                cMonth--;
        }
        var t = "";
        if (cMonth < 1) {
            t += "闰";
            t += mons.charAt(-cMonth - 1);
        }
        else t += mons.charAt(cMonth - 1);
        t += "月";
        t += (total < 11) ? "初" : ((total < 20) ? "十" : ((total < 30) ? "廿" : "卅"));
        if (total % 10 != 0 || total == 10) t += "一二三四五六七八九十".charAt((total - 1) % 10);

        return returnDate ? new Date(cYear+'/'+cMonth+'/'+total) : cYear + '年' + t;
    } : function (d) {
        var LunarYear = d.getFullYear(),
            LunarMonth = d.getMonth() + 1,
            LunarDate = d.getDate(),
            acc = 0,
            leap, SolarDate, y, im, lm;
        if (LunarYear < FIRSTYEAR || LunarYear >= LASTYEAR) {
            alert('只处理1936 - 2031有效年份');
            return false;
        }
        y = LunarYear - FIRSTYEAR;
        im = LunarCal[y].Intercalation;
        lm = LunarMonth;
        if (lm < 0) {
            if (lm != -im) {
                alert('月份无效');
                return false;
            }
        }
        else if (lm < 1 || lm > 12) {
            alert('月份无效');
            return false;
        }
        if (im != 0) {
            if (lm > im) {
                lm++;
            } else if (lm == -im) {
                lm = im + 1;
            }
        }
        lm--;
        if (LunarDate > LunarCal[y].MonthDays[lm] + 29) {
            alert('农历日期不正确');
            return false;
        }
        for (i = 0; i < lm; i++) {
            acc += LunarCal[y].MonthDays[i] + 29;
        }
        acc += LunarCal[y].BaseDays + LunarDate;
        leap = GetLeap(LunarYear);
        for (i = 13; i >= 0; i--) {
            if (acc > SolarDays[leap * 14 + i])
                break;
        }
        SolarDate = acc - SolarDays[leap * 14 + i];
        if (i <= 11) {
            SolarYear = LunarYear;
            SolarMonth = i + 1;
        } else {
            SolarYear = LunarYear + 1;
            SolarMonth = i - 11;
        }
        leap = GetLeap(SolarYear);
        y = SolarYear - FIRSTYEAR;
        acc = SolarDays[leap * 14 + SolarMonth - 1] + SolarDate;
        weekday = (acc + LunarCal[y].BaseWeekDay) % 7;
        kc = acc + LunarCal[y].BaseKanChih;
        kan = kc % 10;
        chih = kc % 12;
        return returnDate ? new Date(SolarYear + '/' + SolarMonth + '/' + SolarDate) : SolarYear + '-' + SolarMonth + '-' + SolarDate;
    }
    return func(date);
}
WinsenJiansbomber
WinsenJiansbomber   2016.03.05 15:23

OMG,这不是字符串的替换,至于搞个代码把浏览器都撑高了吗

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!