1

我必须Date从 javascript 将当前日期的对象发送到我的后端

我正在做的是

var currentDate = new Date();
var dateString = currentDate.getMonth() + "-"
  + currentDate.getDate() + "-" + currentDate.getFullYear() + " "
  + currentDate.getHours() + ":" + currentDate.getMinutes() + ":"
  + currentDate.getSeconds();
var newDate = new Date(Date.parse(dateString));

但它说无效newDate日期。

我必须将 3-10-2013 6:10:25 PM 作为日期时间对象发送到后端。

4

2 回答 2

0
var currentDate = new Date(),
    utcYear = currentDate.getUTCFullYear(),
    utcMonth = ('0' + currenctDate.getUTCMonth()).slice(-2),
    utcDay = ('0' + currentDate.getUTCDate()).slice(-2),
    fullDateString = utcMonth.toString() + '/' + utcDay.toString() + '/' + utcYear.toString();

如果您也想获得时间部分,则同样的原则。

于 2013-04-10T12:27:35.613 回答
-1

不要-在月/日和日期/年之间输入,只需输入空格即可。

var currentDate = new Date(),
    dateString = currentDate.getMonth() + " " + 
                  currentDate.getDate() + " " + 
              currentDate.getFullYear() + " " + 
                 currentDate.getHours() + ":" + 
               currentDate.getMinutes() + ":" + 
               currentDate.getSeconds(),
    newDate = new Date(dateString);

console.log(newDate)
于 2013-04-10T12:28:21.260 回答