zoukankan      html  css  js  c++  java
  • JS获取日期yy-mm-dd格式

    方法一:

    var myDate=new Date(); 
    var month = myDate.getMonth() + 1;
    var Day = myDate.getDate();
    var today = "";
    if(month<10){
    if(Day<10){
    today = myDate.getFullYear() + "-0" + month + "-0" + Day;
    }else{
    today = myDate.getFullYear() + "-0" + month + "-" + Day;
    }
    }
    else{
    if(Day<10){
    today = myDate.getFullYear() + "-" + month + "-0" + Day;
    }else{
    today = myDate.getFullYear() + "-" + month + "-" + Day;
    }
    }
    

    方法二:

    function appendZero(s){return ("00"+ s).substr((s+"").length);}  //补0函数
    var d = new Date();
    alert(d.getFullYear() + "-" + appendZero(d.getMonth() + 1) + "-" + appendZero(d.getDate()));
    

      

  • 相关阅读:
    socket
    netstat
    列表
    突然发现不会写代码了
    算法资源
    bit位操作
    排序算法
    连续子数组最大和
    books
    凸优化
  • 原文地址:https://www.cnblogs.com/littleCode/p/3708380.html
Copyright © 2011-2022 走看看