如何更改日期格式并在jquery中添加日期

时间:2014-02-18 12:07:54

标签: jquery

我有这种格式的日期18/02/2014我只需要添加7天。有人可以帮忙吗?我试过这种方式

var cur_date = new Date("27/02/2014");
var next_date = cur_date.setDate(cur_date.getDate() + 14);
alert(next_date) 

但它返回:1458064800000

2 个答案:

答案 0 :(得分:0)

试试这个:

  var date  =  '18/02/2014'.split('/');   //   convert to array
  date[0]   =  parseInt(date[0])+7;       // add 7 days
  date      =  date.join('/');            // reconstruct date

答案 1 :(得分:0)

在你的JQuery中你可以尝试:

var v = new Date(2014, 02, 18); 
v.setDate(v.getDate() + 7);

参数是一个严格遵循符号的字符串:

NameObject = new Date(year, month, day)

三个参数是逗号分隔的整数。 默认情况下,省略的参数设置为零

相关问题