将jquery中的日期格式更改为c#日期格式

时间:2013-10-23 11:46:50

标签: javascript jquery

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

我怎么能得到这个?

由于

2 个答案:

答案 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