如何通过JavaScript实现公历转换农历2014-09-19 csdn博客 Joyce-Luo相信有人会在页面中中选择日期时,需要知道选择日期的农历!如果是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>代码就已经贴上了,关键这里有一个js:calendar-converter.js,主要是用来公历转换农历的!附上该资源下载地址:http://download.csdn.net/download/luo201227/7616913最后给大伙儿贴上几张效果图:1:

2:

3: