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
我怎么能得到这个?
由于
答案 0 :(得分:3)
您需要使用API格式化日期对象:
var str = lastday.getDate() + "/" + (lastday.getMonth() + 1) + "/" + lastday.getFullYear();
答案 1 :(得分: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