zoukankan      html  css  js  c++  java
  • 获取不同时间类型

    //获取本月份

     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 }
  • 相关阅读:
    投影机的选择
    IOS 检测摇动
    MARK 我的第一个app完成
    2013年会抽奖程序
    给phpcms v9增加类似于phpcms 2008中的关键词表
    codeigniter 用.htcaccess做动态二级域名解析
    获取优酷、土豆、搜狐视频 HTML5视频m3u8格式源
    发现一个好的文学素材类网站
    mac MAMP下安装mongdb & RockMongo
    给artDialog 5.02 增加ajax get功能
  • 原文地址:https://www.cnblogs.com/wxw1314/p/6844804.html
Copyright © 2011-2022 走看看