问题描述
- 求大神解答 c币多多 感谢了
-
如图片一样 计算俩个日期之间的时间差
并且更改开始时间或截止时间是下方的阴历开始跟截止同样改变,改变成同一天
大神帮帮小弟 最好带注释 感谢了
<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> <form name="reg_testdate" method="post" class="date"> <select name="YYYY" onChange="YYYYDD(this.value)"></select><span>年</span> <select name="MM" onChange="MMDD(this.value)"> </select><span>月</span> <select name="DD" ></select><span>日</span> </form> <form name="reg_testdate4" method="post" class="date4"> <select name="YYYY4" onChange="YYYYDD4(this.value)"></select><span>年</span> <select name="MM4" onChange="MMDD4(this.value)"> </select><span>月</span> <select name="DD4" ></select><span>日</span> </form> <form name="reg_testdate1" method="post" class="date1"> <select name="YYYY1" onChange="YYYYDD1(this.value)"></select><span>年</span> <select name="MM1" onChange="MMDD1(this.value)"> </select><span>月</span> <select name="DD1" ></select> </form> <form name="reg_testdate3" method="post" class="date3"> <select name="YYYY3" onChange="YYYYDD3(this.value)"></select><span>年</span> <select name="MM3" onChange="MMDD3(this.value)"> </select><span>月</span> <select name="DD3" ></select> </form> <form name="reg_testdate2" id="jg" class="date2"> <input type="text" class="tet" onChange="YYYYDD2(this.value)"/><span>年</span> <input type="text" class="tet" onChange="MMDD2(this.value)"/><span>月</span> <input type="text" class="tet"/><span>周</span> <input type="text" class="tet"/><span>日</span> <input type="text" class="tet"/><span>小时</span> <input type="text" class="tet"/><span>分钟</span> <input type="text" class="tet"/><span>秒</span> </form> </div> </div>
解决方案
js阴历阳历转换
http://www.cnblogs.com/zhaoshun/archive/2008/12/24/1361623.html
计算时间将年月日组合成 '2015/12/15'字符串,然后new Date( '2015/12/15')得到日期对象,调用getTime()得到时间戳,两个时间戳相减得到毫秒,转换换天小时这种就不用多说了吧
解决方案二:
首先,你要给这些下拉列表添加onblur时间,当鼠标移除的时候,以阳历开始时间为例:
第一步:获取初始年份的值,月份的值,日期的值,拼接起来,转换日期格式
第二步: 根据阳历获取阴历的值,并修改阴历的值
第三步:获取结束年份的值,月份的值,日期的值,拼接起来,转换日期格式
第四部:结束日期-开始日期得到差值
获取差值年份,月份,日期的值,分别赋给相应的text,至于周就不用算了,没有多大意义
小时分钟秒因为你没传值,索引都默认为00
解决方案三:
有点小复杂,帮顶,给几个C吧
解决方案四:
这是我写的转阴历的例子,直接就可以引用:
js:
<br>
var lunarInfo=new Array(<br><br>
0x04bd8,0x04ae0,0x0a570,0x054d5,0x0d260,0x0d950,0x16554,0x056a0,0x09ad0,0x055d2,<br><br>
0x04ae0,0x0a5b6,0x0a4d0,0x0d250,0x1d255,0x0b540,0x0d6a0,0x0ada2,0x095b0,0x14977,<br><br>
0x04970,0x0a4b0,0x0b4b5,0x06a50,0x06d40,0x1ab54,0x02b60,0x09570,0x052f2,0x04970,<br><br>
0x06566,0x0d4a0,0x0ea50,0x06e95,0x05ad0,0x02b60,0x186e3,0x092e0,0x1c8d7,0x0c950,<br><br>
0x0d4a0,0x1d8a6,0x0b550,0x056a0,0x1a5b4,0x025d0,0x092d0,0x0d2b2,0x0a950,0x0b557,<br><br>
0x06ca0,0x0b550,0x15355,0x04da0,0x0a5d0,0x14573,0x052d0,0x0a9a8,0x0e950,0x06aa0,<br><br>
0x0aea6,0x0ab50,0x04b60,0x0aae4,0x0a570,0x05260,0x0f263,0x0d950,0x05b57,0x056a0,<br><br>
0x096d0,0x04dd5,0x04ad0,0x0a4d0,0x0d4d4,0x0d250,0x0d558,0x0b540,0x0b5a0,0x195a6,<br><br>
0x095b0,0x049b0,0x0a974,0x0a4b0,0x0b27a,0x06a50,0x06d40,0x0af46,0x0ab60,0x09570,<br><br>
0x04af5,0x04970,0x064b0,0x074a3,0x0ea50,0x06b58,0x055c0,0x0ab60,0x096d5,0x092e0,<br><br>
0x0c960,0x0d954,0x0d4a0,0x0da50,0x07552,0x056a0,0x0abb7,0x025d0,0x092d0,0x0cab5,<br><br>
0x0a950,0x0b4a0,0x0baa4,0x0ad50,0x055d9,0x04ba0,0x0a5b0,0x15176,0x052b0,0x0a930,<br><br>
0x07954,0x06aa0,0x0ad50,0x05b52,0x04b60,0x0a6e6,0x0a4e0,0x0d260,0x0ea65,0x0d530,<br><br>
0x05aa0,0x076a3,0x096d0,0x04bd7,0x04ad0,0x0a4d0,0x1d0b6,0x0d250,0x0d520,0x0dd45,<br><br>
0x0b5a0,0x056d0,0x055b2,0x049b0,0x0a577,0x0a4b0,0x0aa50,0x1b255,0x06d20,0x0ada0) </p>
<p>var solarMonth=new Array(31,28,31,30,31,30,31,31,30,31,30,31);<br><br>
var Gan=new Array("甲","乙","丙","丁","戊","己","庚","辛","壬","癸");<br><br>
var Zhi=new Array("子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥");<br><br>
var Animals=new Array("鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪");<br><br>
var solarTerm = new Array("小寒","大寒","立春","雨水","惊蛰","春分","清明","谷雨","立夏","小满","芒种","夏至","小暑","大暑","立秋","处暑","白露","秋分","寒露","霜降","立冬","小雪","大雪","冬至")<br><br>
var sTermInfo = new Array(0,21208,42467,63836,85337,107014,128867,150921,173149,195551,218072,240693,263343,285989,308563,331033,353350,375494,397447,419210,440795,462224,483532,504758)<br><br>
var nStr1 = new Array('日','一','二','三','四','五','六','七','八','九','十')<br><br>
var nStr2 = new Array('初','十','廿','卅',' ')<br><br>
var monthName = new Array("JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC"); </p>
<p>/*****************************************************************************<br><br>
日期计算<br><br>
*****************************************************************************/ </p>
<p>//====================================== 传回农历 y年的总天数<br><br>
function lYearDays(y) {<br><br>
var i, sum = 348<br><br>
for(i=0x8000; i>0x8; i>>=1) sum += (lunarInfo[y-1900] & i)? 1: 0<br><br>
return(sum+leapDays(y))<br><br>
} </p>
<p>//====================================== 传回农历 y年闰月的天数<br><br>
function leapDays(y) {<br><br>
if(leapMonth(y)) return((lunarInfo[y-1900] & 0x10000)? 30: 29)<br><br>
else return(0)<br><br>
} </p>
<p>//====================================== 传回农历 y年闰哪个月 1-12 , 没闰传回 0<br><br>
function leapMonth(y) {<br><br>
return(lunarInfo[y-1900] & 0xf)<br><br>
} </p>
<p>//====================================== 传回农历 y年m月的总天数<br><br>
function monthDays(y,m) {<br><br>
return( (lunarInfo[y-1900] & (0x10000>>m))? 30: 29 )<br><br>
} </p>
<p>//====================================== 算出农历, 传入日期物件, 传回农历日期物件<br><br>
// 该物件属性有 .year .month .day .isLeap .yearCyl .dayCyl .monCyl<br><br>
function Lunar(objDate) { </p>
<pre><code> var i, leap=0, temp=0
var baseDate = new Date(1900,0,31)
var offset = (objDate - baseDate)/86400000
this.dayCyl = offset + 40
this.monCyl = 14
for(i=1900; i<2050 && offset>0; i++) {
temp = lYearDays(i)
offset -= temp
this.monCyl += 12
}
if(offset<0) {
offset += temp;
i--;
this.monCyl -= 12
}
this.year = i
this.yearCyl = i-1864
leap = leapMonth(i) //闰哪个月
this.isLeap = false
for(i=1; i<13 && offset>0; i++) {
//闰月
if(leap>0 && i==(leap+1) && this.isLeap==false)
{ --i; this.isLeap = true; temp = leapDays(this.year); }
else
{ temp = monthDays(this.year, i); }
//解除闰月
if(this.isLeap==true && i==(leap+1)) this.isLeap = false
offset -= temp
if(this.isLeap == false) this.monCyl ++
}
if(offset==0 && leap>0 && i==leap+1)
if(this.isLeap)
{ this.isLeap = false; }
else
{ this.isLeap = true; --i; --this.monCyl;}
if(offset<0){ offset += temp; --i; --this.monCyl; }
this.month = i
this.day = offset + 1
}
</code></pre>
<p>//==============================传回国历 y年某m+1月的天数<br><br>
function solarDays(y,m) {<br><br>
if(m==1)<br><br>
return(((y%4 == 0) && (y%100 != 0) || (y%400 == 0))? 29: 28)<br><br>
else<br><br>
return(solarMonth[m])<br><br>
}<br><br>
//============================== 传入 offset 传回干支, 0=甲子<br><br>
function cyclical(num) {<br><br>
return(Gan[num%10]+Zhi[num%12])<br><br>
} </p>
<p>//====================== 中文日期<br><br>
function cDay(d){<br><br>
var s; </p>
<pre><code> switch (d) {
case 10:
s = '初十'; break;
case 20:
s = '二十'; break;
break;
case 30:
s = '三十'; break;
break;
default :
s = nStr2[Math.floor(d/10)];
s += nStr1[d%10];
}
return(s);
</code></pre>
<p>}<br><br>
//====================== 中文月份<br><br>
function cMonth(m){<br><br>
var s;<br><br>
switch (m) {<br><br>
case 1:<br><br>
s = '正月'; break;<br><br>
case 2:<br><br>
s = '二月'; break;<br><br>
case 3:<br><br>
s = '三月'; break;<br><br>
case 4:<br><br>
s = '四月'; break;<br><br>
case 5:<br><br>
s = '五月'; break;<br><br>
case 6:<br><br>
s = '六月'; break;<br><br>
case 7:<br><br>
s = '七月'; break;<br><br>
case 8:<br><br>
s = '八月'; break;<br><br>
case 9:<br><br>
s = '九月'; break;<br><br>
case 10:<br><br>
s = '十月'; break;<br><br>
case 11:<br><br>
s = '十一月'; break;<br><br>
case 12:<br><br>
s = '十二月'; break;<br><br>
default :<br><br>
break;<br><br>
}<br><br>
return(s);<br><br>
}<br>
function cYear(y){<br>
return(y+'年'); <br>
}<br><br>
function GetLunarDay() {<br>
var year=document.getElementById("year").value; <br>
var month=document.getElementById("month").value; <br>
var day=document.getElementById("day").value; <br>
var sDObj=new Date(parseInt(year),parseInt(month),parseInt(day));<br><br>
var lDObj=new Lunar(sDObj);<br>
alert(cYear(lDObj.year)+cMonth(lDObj.month)+cDay(lDObj.day)); //农历<br><br>
return cMonth(lDObj.month)+cDay(lDObj.day);<br><br>
}<br><br>
下面是标签:
年度: 月份: 日期:
解决方案五:
上面粘错了,以这个为准
```<%@ 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">
月份: 日期:
解决方案六:
貌似不能回答这么多字,要不你访问我的资源地址吧http://download.csdn.net/detail/meng20166/9358279