国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

javascript顯示上周、上個(gè)月日期的處理方法

2019-11-20 10:37:10
字體:
供稿:網(wǎng)友

本文實(shí)例介紹了javascript一周前、一個(gè)月前的實(shí)現(xiàn)代碼,對于javascript日期處理進(jìn)行了簡單分析,分享給大家供大家參考,具體內(nèi)容如下

<html><head> <title></title> <script src="../Script/jQuery/jquery-1.6.2.min.js" type="text/javascript"></script> <script src="../Script/MTHCRMWidget/MTHCRMWidget.js" type="text/javascript"></script> <script type="text/javascript">  $(function () {   myClick();//點(diǎn)擊事件觸發(fā)  })  //專門包裝點(diǎn)擊事件;  function myClick() {   $(".tbBtn").click(function () {    var sid = $(this).attr("id");    var agoDate = "";    var Cdate = new Date();    if (sid == "CbtnNull") {     $("#txtCallCycleBegin").val("");     $("#txtCallCyclecurrend").val("");    } else if (sid == "CbtnMoon") {     agoDate = ProcessDate(30);     $("#txtCallCycleBegin").val("{0}-{1}-{2}".format(agoDate.Year, agoDate.Moon, agoDate.Day));     $("#txtCallCyclecurrend").val("{0}-{1}-{2}".format(Cdate.getFullYear(), Cdate.getMonth() + 1, Cdate.getDate()));    } else {     agoDate = ProcessDate(7);     $("#txtCallCycleBegin").val("{0}-{1}-{2}".format(agoDate.Year, agoDate.Moon, agoDate.Day));     $("#txtCallCyclecurrend").val("{0}-{1}-{2}".format(Cdate.getFullYear(), Cdate.getMonth() + 1, Cdate.getDate()));    }   })  }  //處理日期的函數(shù),返回一個(gè)字面量;  function ProcessDate(type) {   //1.0獲取現(xiàn)在時(shí)間的年月日:   var currentTime = new Date("2016-01-02"); //得到當(dāng)前的時(shí)間   var currentYear = currentTime.getFullYear(); //得到當(dāng)前的年份   var currentMoon = currentTime.getMonth() + 1; //得到當(dāng)前的月份(系統(tǒng)默認(rèn)為0-11,所以要加1才算是當(dāng)前的月份)   var currentDay = currentTime.getDate(); //得到當(dāng)前的天數(shù)   //2.0獲取當(dāng)前時(shí)間的一個(gè)月內(nèi)的年月日:(一個(gè)月內(nèi)的大眾業(yè)務(wù)需求為:當(dāng)前時(shí)間的月份-1,當(dāng)前時(shí)間的天數(shù)+1)   var agoDay = "";   var agoMoon = currentMoon;   var agoYear = currentYear;   var max = "";   switch (type) {    case 30:     agoDay = currentDay + 1;     agoMoon = currentMoon - 1;     max = new Date(agoYear, agoMoon, 0).getDate(); //獲取上個(gè)月的總天數(shù)     break;    case 7:     agoDay = currentDay - 6;     if (agoDay < 0) {      agoMoon = currentMoon - 1;//月份減1      max = new Date(agoYear, agoMoon, 0).getDate(); //獲取上個(gè)月的總天數(shù)      agoDay = max + agoDay;//天數(shù)在上個(gè)月的總天數(shù)的基礎(chǔ)上減去負(fù)數(shù)     }     break;   }   //3.0對處理的年月日作邏輯判斷   //如果beginDay > max(如果是當(dāng)前時(shí)間的天數(shù)+1后的數(shù)值超過了上個(gè)月的總天數(shù): 天數(shù)變?yōu)?,月份增加1)   if (agoDay > max) {    agoDay = 1;    agoMoon += 1;   }   //如果月份當(dāng)月為1月的時(shí)候, 那么一個(gè)月內(nèi): 年:-1 月:12 日:依然不變    if (agoMoon == 0) {    agoMoon = 12;    agoYear = currentYear - 1;   }   //4.0對已經(jīng)處理好的數(shù)據(jù)作格式處理(單位數(shù)則自動補(bǔ)零)   currentMoon = Appendzero(currentMoon);   currentDay = Appendzero(currentDay);   agoMoon = Appendzero(agoMoon);   agoDay = Appendzero(agoDay);   //5.0幫助代碼   console.log("當(dāng)前時(shí)間為:{0}-{1}-{2}".format(currentYear, currentMoon, currentDay));   console.log("一個(gè)月前的時(shí)間為{0}-{1}-{2}".format(agoYear, agoMoon, agoDay));   return { "Year": agoYear, "Moon": agoMoon, "Day": agoDay };  }  //處理各位數(shù)為零的數(shù)字(單位數(shù)則加0)  function Appendzero(obj) {   if (obj < 10) {    return "0" + obj;   } else {     return obj;   }  } </script></head><body> <input type="button" class="tbBtn" id="CbtnNull" style="background-color:#e3e3e3" value="不限"/> <input type="button" class="tbBtn" id="CbtnMoon" style="width: 80px; margin-left: 5px; margin-right: 5px;" value="一個(gè)月內(nèi)"/> <input type="button" class="tbBtn" id="CbtnWeek" style="width: 80px; margin-left: 5px; margin-right: 5px;" value="一周內(nèi)"/> <input id = "txtCallCycleBegin" type="text"/> <input id = "txtCallCyclecurrend" type="text"/></body></html>

以上就是本文的全部內(nèi)容,希望能夠幫助大家更好的解決javascript日期處理問題。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 太白县| 通辽市| 阜新| 油尖旺区| 项城市| 嘉峪关市| 清新县| 永福县| 新竹市| 肥乡县| 怀仁县| 沈阳市| 乌鲁木齐市| 石嘴山市| 天津市| 个旧市| 巨野县| 肃宁县| 田东县| 巨鹿县| 武宁县| 景宁| 公主岭市| 甘肃省| 平乡县| 碌曲县| 小金县| 花莲市| 天峻县| 嘉善县| 射阳县| 扎赉特旗| 丽水市| 合山市| 巴林右旗| 长顺县| 平凉市| 灵石县| 友谊县| 山西省| 玛沁县|