0

javascript代码是

 var lastday = new Date(curr.setDate(curr.getDate() - curr.getDay() + 5));

我得到输出

Fri Oct 25 2013 17:15:12 GMT+0530 (India Standard Time)

输出是正确的,但我想要输出类似

25/10/2013

我怎样才能得到这个?

谢谢

4

2 回答 2

3

您需要使用 API 格式化日期对象:

var str = lastday.getDate() + "/" + (lastday.getMonth() + 1) + "/" + lastday.getFullYear();
于 2013-10-23T11:49:30.457 回答
0

是的,你可以这样做:

var lastday = new Date(curr.setDate(curr.getDate() - curr.getDay() + 5));

var date = lastday.getDate();

// 1 is added since it's zero-based value 
// (where zero indicates the first month of the year).
var month = lastday.getMonth() + 1;      
var year = lastday.getFullYear();

// You can change the format to like 'dd/mm/yyyy' or 'mm/dd/yyyy'
// based on your requirements below
var newDate = date + '/' + month + '/' + year;


console.log(newDate); // 25/10/2013
于 2013-10-23T11:57:16.023 回答