javascript日期相加函数

2019-03-11 23:22|来源: 网络

javascript日期相加函数

//addDate("5",5,"2004/12/1 00:00:00")


function  addDate(type,NumDay,dtDate) {

   var  date  =   new  Date(dtDate);

   type  =  parseInt(type);  // 类型  

   lIntval  =  parseInt(NumDay); // 间隔

   switch (type) {

       case   6  : // 年

           date.setYear(date.getYear()  +  lIntval)

           break ;

       case   7  : // 季度

           date.setMonth(date.getMonth()  +  (lIntval  *   3 ) )

           break ;

       case   5  : // 月

           date.setMonth(date.getMonth()  +  lIntval)

           break ;

       case   4  : // 天

           date.setDate(date.getDate()  +  lIntval)

           break

       case   3  : // 时

           date.setHours(date.getHours()  +  lIntval)

           break

       case   2  : // 分

           date.setMinutes(date.getMinutes()  +  lIntval)

           break

       case   1  : // 秒

           date.setSeconds(date.getSeconds()  +  lIntval)

           break ;

       default :

   }  

   return  date.getYear()  + ' - '  +   (date.getMonth() + 1 )  +  ' - '  + date.getDate() +  ' ' +  date.getHours() + ':' + date.getMinutes() + ':' + date.getSeconds()

}  


本文链接:http://www.656463.com/article/551,转自:http://www.blogjava.net/duansky/archive/2009/09/19/295655.html

相关问答

更多
  • time.strftime("%H", time.localtime(time.time()+2*60*60))
  • 我是不是可以理解成为 sheet2表 A1是算的sheet1表的A2:A11 A2是算的sheet1表的A12:A21 A3是算的sheet1表的A22:A31 依此类推? 如果是, 你的sheet2表A1输入 =SUM(INDIRECT("SHEET1!A"&(ROW(A1)-1)*10+2&":A"&(ROW(A1)-1)*10+11)) 下拉公式即可
  • 我测试了你的代码: // create a date object for this Friday: var d = new Date(2012, 0, 20); //override Date constructor so all newly constructed dates return this Friday Date = function(){return d;}; var now = new Date() console.log(now); now = new Date() console. ...
  • 这对我来说在64位系统上运行正常。 如果您使用的是32位系统,则99999999999不适合Int,因此它会溢出并给出错误的结果。 如果将类型更改为Integer,则应该可以正常工作。 This works fine for me on a 64-bit system. If you're on a 32 bit system, 99999999999 doesn't fit into an Int, so it will overflow and give you wrong results. If yo ...
  • 从ECMAScript规范 : 自UTC时间1970年1月1日起,时间以ECMAScript为单位,以毫秒为单位。 在时间值中,忽略闰秒。 假设每天恰好有86,400,000毫秒。 ECMAScript数值可以表示从-9,007,199,254,740,991到9,007,199,254,740,991的所有整数; 此范围足以测量从UTC时间1970年1月1日起向前或向后约285,616年内的任何瞬间的毫秒精度。 ECMAScript日期对象支持的实际时间范围略小:相对于UTC时间1970年1月1日午夜测量 ...
  • 我重构了你的代码。 这是它的JSFiddle: https ://jsfiddle.net/vytfeq8k/ HTML:
    使用Javascript: