zoukankan      html  css  js  c++  java
  • javascript获得给定日期的前一天的日期

     1 /**
     2 * 获得当前日期的前一天
     3 */
     4 function getYestoday(date){    
     5   var yesterday_milliseconds=date.getTime()-1000*60*60*24;//转换成毫秒后减去一天的毫秒数
     6 // var yesterday = new Date();     
     7 // yesterday.setTime(yesterday_milliseconds);     
     8 //           
     9 // var strYear = yesterday.getFullYear();  
    10 // var strDay = yesterday.getDate();  
    11 // var strMonth = yesterday.getMonth()+1;
    12 // if(strMonth<10)  
    13 // {  
    14 //   strMonth="0"+strMonth;  
    15 // }  
    16    //datastr = strYear+"-"+strMonth+"-"+strDay;
    17    return new Date(yesterday_milliseconds);
    18 }

    大家可根据上面方法扩展获得前一个月的日期、前一年的日期,被注释掉的部分可以转换成你想要的日期格式。

    js日期的构造函数:

    1 new Date() 
    2 new Date(milliseconds) 
    3 new Date(datestring) 
    4 new Date(year, month) 
    5 new Date(year, month, day) 
    6 new Date(year, month, day, hours) 
    7 new Date(year, month, day, hours, minutes) 
    8 new Date(year, month, day, hours, minutes, seconds) 
    9 new Date(year, month, day, hours, minutes, seconds, microseconds) 

    具体方法可在这里http://blog.sina.com.cn/s/blog_6a0cd5e501011so7.html浏览

  • 相关阅读:
    [恢]hdu 2005
    [恢]hdu 2004
    [恢]hdu 1093
    [恢]hdu 1092
    [恢]hdu 2008
    [恢]hdu 1091
    [恢]hdu 2006
    [恢]hdu 1089
    [恢]hdu 1094
    OGRE小记
  • 原文地址:https://www.cnblogs.com/smallrock/p/3529021.html
Copyright © 2011-2022 走看看