2014-11-05 71 views
0

即時通訊使用jquery做日期過濾器,當我發送日期到服務器即時通訊發送一個不同的日期,從我在模型中有。可以說我選擇2014年10月27日至2014年10月27日。jquery datepicker返回前一天

var fromDate = new Date($scope.date.from); //Mon Oct 27 2014 00:00:00 GMT+0200 
var toDate = new Date($scope.date.to); // Mon Oct 27 2014 00:00:00 GMT+0200 

和向服務器發送的數據是:

2014-10-26T22:00:00.000Z 
2014-10-26T22:00:00.000Z 

這是前一天。爲什麼發生這種情況?使用

+0

你把它發送到服務器之前將其轉換爲UTC日期格式? – 2014-11-05 08:14:37

+0

不,這是我唯一的代碼。我需要添加什麼? – Bazinga 2014-11-05 08:15:17

+0

創建一個小提琴 – 2014-11-05 08:16:56

回答

0

所以答案,使這項工作是這樣的:

var DateFrom = new Date(Date.UTC(fromDate.getFullYear(),fromDate.getMonth(),fromDate.getDate(),0,0,0,0)); 

     var DateTo = new Date(Date.UTC(toDate.getFullYear(),toDate.getMonth(),toDate.getDate(),23,59,59,0)); 
0

請嘗試以下

var fromDate = new Date($scope.date.from).toUTCString(); 

有與時區差異的問題。

+0

當我做這我得到:太陽,2014年10月26日22:00:00 GMT仍然不工作 – Bazinga 2014-11-05 08:22:32

+0

@anguLaravel,你會得到UTC時間。將其轉換爲您的TimeZone與服務器代碼.. – Anujith 2014-11-05 08:24:02

+0

您也正在發送2014-10-26T22:00:00,這是2014年10月26日,22.00 – Indra 2014-11-05 08:24:18