• 获取不同时间类型


    //获取本月份

     1 function getNewMonth(){
     2     var date=new Date;
     3     var year=date.getFullYear(); 
     4     var month=date.getMonth()+1;
     5     if(month<10){
     6         month="0"+month;
     7     }else{
     8         month=month;
     9     }
    10     return year+"-"+month
    11 }

    //获取当前时间

     1 function getNewTime(){
     2     var date = new Date;
     3     var year = date.getFullYear();
     4     var month = date.getMonth()+1;
     5     var day = date.getDate();
     6     var hour = date.getHours();
     7     var minute = date.getMinutes();
     8     var second = date.getSeconds();
     9     if(month<10){
    10         month="0"+month;
    11     }else{
    12         month=month;
    13     }
    14     if(day<10){
    15         day="0"+day;
    16     }else{
    17         day=day;
    18     }
    19     if(hour<10){
    20         hour="0"+day;
    21     }else{
    22         hour=hour;
    23     }
    24     if(minute<10){
    25         minute="0"+minute;
    26     }else{
    27         minute=minute;
    28     }
    29     if(second<10){
    30         second="0"+second;
    31     }else{
    32         second=second;
    33     }
    34     return year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second;
    35 }

    //获取当前日期

     1 function getNewDate(){
     2     var date = new Date;
     3     var year = date.getFullYear();
     4     var month = date.getMonth()+1;
     5     var day = date.getDate();
     6     if(month<10){
     7         month="0"+month;
     8     }else{
     9         month=month;
    10     }
    11     if(day<10){
    12         day="0"+day;
    13     }else{
    14         day=day;
    15     }
    16     return year+"-"+month+"-"+day;
    17 }

    // 获取一周后日期

     1 function WeeklAgoDate(op){
     2     var now = new Date();
     3     var nowDayOfWeek = now.getDay();
     4     var date = new Date(now.getTime() + 7 * 24 * 3600 * 1000);
     5     var year = date.getFullYear();
     6     var month = date.getMonth() + 1;
     7     if(month<10){
     8         month="0"+month;
     9     }else{
    10         month=month;
    11     }
    12     var day = date.getDate();
    13     if(day<10){
    14         day="0"+day;
    15     }else{
    16         day=day;
    17     }
    18     var op = year + '-' + month + '-' + day;
    19     return op;
    20 }
  • 相关阅读:
    hdu 5723 Abandoned country 最小生成树 期望
    OpenJ_POJ C16G Challenge Your Template 迪杰斯特拉
    OpenJ_POJ C16D Extracurricular Sports 打表找规律
    OpenJ_POJ C16B Robot Game 打表找规律
    CCCC 成都信息工程大学游记
    UVALive 6893 The Big Painting hash
    UVALive 6889 City Park 并查集
    UVALive 6888 Ricochet Robots bfs
    UVALive 6886 Golf Bot FFT
    UVALive 6885 Flowery Trails 最短路
  • 原文地址:https://www.cnblogs.com/wxw1314/p/6844804.html
Copyright © 2020-2023  润新知