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

首頁 > 開發 > JS > 正文

javascript顯示上周、上個月日期的處理方法

2024-05-06 16:27:58
字體:
來源:轉載
供稿:網友
這篇文章主要為大家分享了關于javascript實現上周、上個月的處理方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下
 

本文實例介紹了javascript一周前、一個月前的實現代碼,對于javascript日期處理進行了簡單分析,分享給大家供大家參考,具體內容如下

<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();//點擊事件觸發  })  //專門包裝點擊事件;  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()));    }   })  }  //處理日期的函數,返回一個字面量;  function ProcessDate(type) {   //1.0獲取現在時間的年月日:   var currentTime = new Date("2016-01-02"); //得到當前的時間   var currentYear = currentTime.getFullYear(); //得到當前的年份   var currentMoon = currentTime.getMonth() + 1; //得到當前的月份(系統默認為0-11,所以要加1才算是當前的月份)   var currentDay = currentTime.getDate(); //得到當前的天數   //2.0獲取當前時間的一個月內的年月日:(一個月內的大眾業務需求為:當前時間的月份-1,當前時間的天數+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(); //獲取上個月的總天數     break;    case 7:     agoDay = currentDay - 6;     if (agoDay < 0) {      agoMoon = currentMoon - 1;//月份減1      max = new Date(agoYear, agoMoon, 0).getDate(); //獲取上個月的總天數      agoDay = max + agoDay;//天數在上個月的總天數的基礎上減去負數     }     break;   }   //3.0對處理的年月日作邏輯判斷   //如果beginDay > max(如果是當前時間的天數+1后的數值超過了上個月的總天數: 天數變為1,月份增加1)   if (agoDay > max) {    agoDay = 1;    agoMoon += 1;   }   //如果月份當月為1月的時候, 那么一個月內: 年:-1 月:12 日:依然不變    if (agoMoon == 0) {    agoMoon = 12;    agoYear = currentYear - 1;   }   //4.0對已經處理好的數據作格式處理(單位數則自動補零)   currentMoon = Appendzero(currentMoon);   currentDay = Appendzero(currentDay);   agoMoon = Appendzero(agoMoon);   agoDay = Appendzero(agoDay);   //5.0幫助代碼   console.log("當前時間為:{0}-{1}-{2}".format(currentYear, currentMoon, currentDay));   console.log("一個月前的時間為{0}-{1}-{2}".format(agoYear, agoMoon, agoDay));   return { "Year": agoYear, "Moon": agoMoon, "Day": agoDay };  }  //處理各位數為零的數字(單位數則加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="一個月內"/> <input type="button" class="tbBtn" id="CbtnWeek" style="width: 80px; margin-left: 5px; margin-right: 5px;" value="一周內"/> <input id = "txtCallCycleBegin" type="text"/> <input id = "txtCallCyclecurrend" type="text"/></body></html>

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



注:相關教程知識閱讀請移步到JavaScript/Ajax教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 奇台县| 邓州市| 高清| 大英县| 靖远县| 金堂县| 邓州市| 长武县| 晋中市| 建德市| 太谷县| 岗巴县| 中西区| 枣庄市| 济宁市| 民和| 肇源县| 柯坪县| 内黄县| 冀州市| 柘城县| 青田县| 弥勒县| 凤城市| 新泰市| 百色市| 盐亭县| 巴塘县| 天柱县| 贞丰县| 怀化市| 乐山市| 牙克石市| 余干县| 北京市| 建瓯市| 岑巩县| 新巴尔虎右旗| 古田县| 商城县| 大安市|