时间计算

时间的阶段性

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="jsGetDate.aspx.cs" Inherits="bindData.connection.jsGetDate" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>取得日期</title> <script type="text/javascript" language="javascript"> function setCurTime(oid) { var now = oid; var year = now.getFullYear(); var month = now.getMonth() + 1; var day = now.getDate(); var hours = now.getHours(); var minutes = now.getMinutes(); var seconds = now.getSeconds(); month = month < 10 ? "0" + month : month; day = day < 10 ? "0" + day : day; hours = hours < 10 ? "0" + hours : hours; minutes = minutes < 10 ? "0" + minutes : minutes; seconds = seconds < 10 ? "0" + seconds : seconds; var time = year + "-" + month + "-" + day + " " + hours + ":" + minutes + ":" + seconds; return time; } var nowDate = new Date(); function getToday() { var year = nowDate.getYear(); var month = Number(nowDate.getMonth()) + 1; var day = nowDate.getDate(); document.getElementById("text_date").value = year + "-" + month + "-" + day; } function getMonth() { var month = nowDate.getMonth() + 1; month = (month < 10) ? '-0' + month : '-' + month; var currentMonth = nowDate.getYear() + month; document.getElementById("text_date").value = currentMonth; } function firstDayByThisWeek() { var weekFirstDay = new Date(nowDate - (nowDate.getDay() - 1) * 86400000); document.getElementById("text_date").value = setCurTime(weekFirstDay); } function endDayByThisWeek() { var weekFirstDay = new Date(nowDate - (nowDate.getDay() - 1) * 86400000); var weekLastDay = new Date((weekFirstDay / 1000 + 6 * 86400) * 1000); document.getElementById("text_date").value = setCurTime(weekLastDay); } function firstDayByThisMonth() { var monthFirstDay = new Date(nowDate.getYear(), nowDate.getMonth(), 1); document.getElementById("text_date").value = setCurTime(monthFirstDay); } function endDayByThisMonth() { var monthFirstDay = new Date(nowDate.getYear(), nowDate.getMonth(), 1); var monthEndDay = new Date(monthFirstDay - 86400000); document.getElementById("text_date").value = setCurTime(monthEndDay); } function firstDayByThisQuarter() { var quarterFirstDay = ""; if (nowDate.getMonth() < 3) { quarterFirstDay = new Date(nowDate.getYear(), 0, 1); } else if (nowDate.getMonth() > 2 && nowDate.getMonth() < 6) { quarterFirstDay = new Date(nowDate.getYear(), 3, 1); } else if (nowDate.getMonth() > 5 && nowDate.getMonth() < 9) { quarterFirstDay = new Date(nowDate.getYear(), 6, 1); } else if (nowDate.getMonth() > 8) { quarterFirstDay = new Date(nowDate.getYear(), 9, 1); } document.getElementById("text_date").value = setCurTime(quarterFirstDay); } function endDayByThisQuarter() { var quarterEndDay = ""; if (nowDate.getMonth() < 3) { quarterEndDay = new Date(nowDate.getYear(), 2, 31); } else if (nowDate.getMonth() > 2 && nowDate.getMonth() < 6) { quarterEndDay = new Date(nowDate.getYear(), 5, 30); } else if (nowDate.getMonth() > 5 && nowDate.getMonth() < 9) { quarterEndDay = new Date(nowDate.getYear(), 8, 30); } else if (nowDate.getMonth() > 8) { quarterEndDay = new Date(nowDate.getYear(), 11, 31); } document.getElementById("text_date").value = setCurTime(quarterEndDay); } function firstMonthByThisQuarter() { var quarterFirstMonth = ""; if (nowDate.getMonth() < 3) { quarterFirstMonth = nowDate.getYear() + '-01'; } else if (nowDate.getMonth() > 2 && nowDate.getMonth() < 6) { quarterFirstMonth = nowDate.getYear() + '-04'; } else if (nowDate.getMonth() > 5 && nowDate.getMonth() < 9) { quarterFirstMonth = nowDate.getYear() + '-07'; } else if (nowDate.getMonth() > 8) { quarterFirstMonth = nowDate.getYear() + '-10'; } document.getElementById("text_date").value = quarterFirstMonth; } function endMonthByThisQuarter() { var quarterEndMonth = ""; if (nowDate.getMonth() < 3) { quarterEndMonth = nowDate.getYear() + '-03'; } else if (nowDate.getMonth() > 2 && nowDate.getMonth() < 6) { quarterEndMonth = nowDate.getYear() + '-06'; } else if (nowDate.getMonth() > 5 && nowDate.getMonth() < 9) { quarterEndMonth = nowDate.getYear() + '-09'; } else if (nowDate.getMonth() > 8) { quarterEndMonth = nowDate.getYear() + '-12'; } document.getElementById("text_date").value = quarterEndMonth; } function firstDayByThisYear() { var yearFirstDay = new Date(nowDate.getYear(), 0, 1); document.getElementById("text_date").value = setCurTime(yearFirstDay); } function endDayByThisYear() { var yearLastDay = new Date(nowDate.getYear(), 11, 31); document.getElementById("text_date").value = setCurTime(yearLastDay); } function firstMonthByThisYear() { var yearFirstMonth = nowDate.getYear() + '-01'; document.getElementById("text_date").value = yearFirstMonth; } function endMonthByThisYear() { var yearEndMonth = nowDate.getYear() + '-12'; document.getElementById("text_date").value = yearEndMonth; } </script> </head> <body> <form id="form1" runat="server"> <div> <input type="text" id="text_date" /> <br /> <input type="button" value="今天" οnclick="getToday();" /> <br /> <input type="button" value="当前月" οnclick="getMonth();" /> <br /> <input type="button" value="本周第一天" οnclick="firstDayByThisWeek();" /> <input type="button" value="本周最后一天" οnclick="endDayByThisWeek();" /> <br /> <input type="button" value="本月第一天" οnclick="firstDayByThisMonth();" /> <input type="button" value="本月最后一天" οnclick="endDayByThisMonth();" /> <br /> <input type="button" value="本季第一天" οnclick="firstDayByThisQuarter();" /> <input type="button" value="本季最后一天" οnclick="endDayByThisQuarter();" /> <br /> <input type="button" value="本季开始年月" οnclick="firstMonthByThisQuarter();" /> <input type="button" value="本季最后年月" οnclick="endMonthByThisQuarter();" /> <br /> <input type="button" value="本年第一天" οnclick="firstDayByThisYear();" /> <input type="button" value="本年最后一天" οnclick="endDayByThisYear();" /> <br /> <input type="button" value="本年开始年月" οnclick="firstMonthByThisYear();" /> <input type="button" value="本年最后年月" οnclick="endMonthByThisYear();" /> </div> </form> </body> </html>


两个时间的比较

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="bindData.connection.WebForm1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript" language="javascript"> function daysBetween(DateOne, DateTwo) { var OneMonth = DateOne.substring(5, DateOne.lastIndexOf('-')); var OneDay = DateOne.substring(DateOne.length, DateOne.lastIndexOf('-') + 1); var OneYear = DateOne.substring(0, DateOne.indexOf('-')); var TwoMonth = DateTwo.substring(5, DateTwo.lastIndexOf('-')); var TwoDay = DateTwo.substring(DateTwo.length, DateTwo.lastIndexOf('-') + 1); var TwoYear = DateTwo.substring(0, DateTwo.indexOf('-')); var cha = ((Date.parse(OneMonth + '/' + OneDay + '/' + OneYear) - Date.parse(TwoMonth + '/' + TwoDay + '/' + TwoYear)) / 86400000); return cha; } function aa() { if (daysBetween("2009-11-09 12:22:24", "2009-11-09 12:22:23") <= 0) { alert("时间一要大于时间二!") return false; } else { alert("ok!") } } </script> </head> <body> <form id="form1" runat="server"> <div> <input type="button" οnclick="aa();" />; </div> </form> </body> </html>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值