zoukankan      html  css  js  c++  java
  • 获取当前日期,例为:2017-07-28

    var day=0;
    var month=0;
    var year=0;
    var today="";
    mydate=new Date();
    mymonth=mydate.getMonth()+1;
    myday= mydate.getDate();
    myyear= mydate.getFullYear();
    year=(myyear > 200) ? myyear : 1900 + myyear;

    if(mymonth >= 10){mymonth=mymonth;}else{mymonth="0" + mymonth;}
    if(myday >= 10){myday=myday;}else{myday="0" + myday;}

    today=year+'-'+mymonth+'-'+myday;//2017-09-05;

    //去除<=10的月份、日期前的0;

    if(mymonth <= 10){

    mymonth = mymonth.replace('0','')

    }else{

    mymonth= mymonth;
    }

    if(myday <= 10){

    myday = myday.replace('0','')

    }else{

    myday= myday;
    }

    //获取当前年月 
    var date=new Date;
    var year=date.getFullYear();
    var month=date.getMonth()+1;
    month =(month<10 ? "0"+month:month);//加0
    var mydate = (year.toString()+'-'+month.toString());

    //获取当前日期
    function getDay(day){
      var today = new Date(); 
      var targetday_milliseconds=today.getTime() + 1000*60*60*24*day; 
      today.setTime(targetday_milliseconds); //注意,这行是关键代码 
      var tYear = today.getFullYear(); 
      var tMonth = today.getMonth(); 
      var tDate = today.getDate(); 
      tMonth = doHandleMonth(tMonth + 1); 
      tDate = doHandleMonth(tDate); 
      return tYear+"-"+tMonth+"-"+tDate; 
    }

    //日期拼接
    function doHandleMonth(month){
      var m = month; 
      if(month.toString().length == 1){ 
        m = "0" + month; 
      } 
      return m; 
    }

    var Yesterday = getDay(-1),Today = getDay(0),Last3days = getDay(-2)+','+getDay(0),Last7days = getDay(-6)+','+getDay(0); //取值

    ゛Toly★小饼干ゞ
  • 相关阅读:
    苹果常识
    Xcode相关路径
    iOS10 Xcode8问题汇总
    摇一摇
    手机端在线预览文件
    生成纯色色块
    django--没有整理,笔记
    httprunnermanager环境搭建 -----转
    httprunner---->最最基础小白笔记
    Oracle 多表联合删除?--转
  • 原文地址:https://www.cnblogs.com/rockyan/p/7244554.html
Copyright © 2011-2022 走看看