Javascript jquery中的日期转换

Javascript jquery中的日期转换,javascript,jquery,Javascript,Jquery,我需要给定日期的DD-MM-YYYY格式 var todaydate = /Date(1394908200000)/; //Serialize date var date = eval("new " + todaydate.replace(/\//g, "")); alert('date is :'+date) 但产出看起来像 date is :Wed Jun 11 2014 00:00:00 GMT+0530 (India Standard Time) 预期产量如: date is :11

我需要给定日期的DD-MM-YYYY格式

var todaydate = /Date(1394908200000)/; //Serialize date
var date = eval("new " + todaydate.replace(/\//g, ""));
alert('date is :'+date)
但产出看起来像

date is :Wed Jun 11 2014 00:00:00 GMT+0530 (India Standard Time)
预期产量如:

date is :11-06-2014
试试这个

var date = new Date(); //new Date(1394908200000)
function convert(str) {
    var date = new Date(str),
        mnth = ("0" + (date.getMonth() + 1)).slice(-2),
        day = ("0" + date.getDate()).slice(-2);
    return [day, mnth, date.getFullYear()].join("-");
}

var final = convert(date);
alert('date is :' + final)
试试这个-

var date = new Date();

function myDateFormatter (dateobject) {
    var d = new Date(dateobject);
    var day = d.getDate();
    var month = d.getMonth() + 1;
    var year = d.getFullYear();
    if (day < 10) {
        day = "0" + day;
    }
    if (month < 10) {
        month = "0" + month;
    }
    var date = day + "-" + month + "-" + year;

    return date;
}; 
var dateformat = myDateFormatter(date);
alert('date is :' + dateformat);

除了其他人提到的JS之外,您还可以使用


那么您将时间戳/长日期格式作为输入?看起来您正在使用odata返回的日期。。如果是这样的话,那就节省一些时间,只需在项目中包含moment.js。它了解这些日期,并提供特殊的格式化功能。
var dt = $.datepicker.formatDate('dd-mm-yy', new Date(1394908200000));

alert(dt);