如何通過JavaScript實現西曆轉換農曆

來源:互聯網
上載者:User

相信有人會在頁面中中選擇日期時,需要知道選擇日期的農曆!如果是Java的話,在後台一下子就可以給轉換掉,但是頁面上,通過JavaScript來轉換的話,不知道大伙兒有沒有好的想法呢?剛好,前一段時間來,朋友問了這麼一個問題,然後就寫了一個demo給她,還行吧!希望能幫到有需要的各位,好啦,直接上代碼,不想閑扯:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  <%  String path = request.getContextPath();  String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";  %>        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  <html>    <head>      <base href="<%=basePath%>">                <title>mydate.jsp</title>                <meta http-equiv="pragma" content="no-cache">      <meta http-equiv="cache-control" content="no-cache">      <meta http-equiv="expires" content="0">          <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">      <meta http-equiv="description" content="This is my page">      <!--     <link rel="stylesheet" type="text/css" href="styles.css">     -->    <link rel="stylesheet" type="text/css" href="My97DatePicker/skin/WdatePicker.css">                <style type="text/css">          body {              font-family: 微軟雅黑;              font-size: 14px;              }                    </style>                <script type="text/javascript" src="My97DatePicker/calendar-converter.js"></script>      <script type="text/javascript" src="My97DatePicker/WdatePicker.js"></script>      <script type="text/javascript" src="jQuery/jquery-1.6.js"></script>    </head>            <body>      <div id="calendar">          <div id="showCalendar"></div>          <div><span id="showSolarCalendar"></span>[<span id="showLunarCalendar"></span>]</div>      </div>    </body>              <script type="text/javascript">          function getLunarCalendar(date){              var cc  = new CalendarConverter;              var result = cc.solar2lunar(date);              return result.cYear + "(" + result.lunarYear + ")年" + (result.isLeap?"閏":"") + result.lunarMonth + "月" + result.lunarDay + " " + result.lunarFestival + " 星期" + result.week;          }                        var nowDate = new Date();          document.getElementById('showSolarCalendar').innerHTML = nowDate.getFullYear() + "-" + (nowDate.getMonth() + 1) + "-" + nowDate.getDate();          document.getElementById('showLunarCalendar').innerHTML = getLunarCalendar(nowDate);          WdatePicker({              eCont:'showCalendar',              onpicked:function(dp){                  document.getElementById('showSolarCalendar').innerHTML = dp.cal.getDateStr();                  document.getElementById('showLunarCalendar').innerHTML = getLunarCalendar(new Date(dp.cal.getDateStr()));              }          });      </script>  </html>

查看本欄目更多精彩內容:http://www.bianceng.cnhttp://www.bianceng.cn/webkf/script/

代碼就已經貼上了,關鍵這裡有一個js:calendar-converter.js,主要是用來西曆轉換農曆的!附上該資源下載地址:http://download.csdn.net/download/luo201227/7616913

最後給大伙兒貼上幾張效果圖:

1:

2:

3:

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.