2016-05-17 46 views
0

我正面臨着一個奇怪的問題。角度/ javascript html輸入類型'時間'顯示錯誤提交時間

以我形式我使用2個輸入,類型爲「時間」:

<div style="float:left;width:50%;"> 
    <div style="background:#efefef;!important;line-height:30px;font-size:14px;text-transform: uppercase;text-align:center;border:none"> 
    Start time 
    <input type="time" name="start_time" formatted-time ng-model="editFields.disable_freelance_start_time" style="width:100%;border:1px solid #ccc;border-right:none;margin-bottom:10px;padding:5px;" /> 
    </div> 
</div> 
<div style="float:left;width:50%"> 
    <div style="background:#efefef;!important;line-height:30px;font-size:14px;text-transform: uppercase;text-align:center;border:none;border-left:2px solid #ccc"> 
    End time 
    <input type="time" name="end_time" formatted-time ng-model="editFields.disable_freelance_end_time" style="width:100%;border:1px solid #ccc;border-left:none;margin-bottom:10px;padding:5px;" /> 
    </div> 
</div> 

和在我的控制器設置我的模型:

$scope.editFields.disable_freelance_start_time = new Date(); 
    $scope.editFields.disable_freelance_end_time = new Date(); 

並在視圖它示出了在合適的時間輸入 - 當前時間(見屏幕截圖)enter image description here

但是當我「提交表單」並檢查對象時,它顯示錯誤的值 - 時間是2個小時了..(我住在阿姆斯特丹, ?或許真的與夏令)

它顯示了這一點:

[start_time] => 2016-05-17T01:21:56.382Z 
[end_time] => 2016-05-17T01:21:56.382Z 

所以它顯示1:21,但現在是03:21 - 這究竟是爲什麼以及如何解決這個問題?

+0

其正常,獲得TimeZoneOffset,這是在幾分鐘內,你可以手動計算。 – YOU

+0

請注意時區爲Z或GMT。阿姆斯特丹是GMT + 0200,「2016-05-17T01:21:56.382Z」與「2016-05-17T03:21:56.382 + 0200」的時間相同。 – RobG

+0

我明白,但我把這個發送到我的PHP後端,我把它作爲一個字符串。我應該在PHP中處理這個嗎? – rZaaaa

回答

0

似乎你有問題和時區。這個問題也有我。我用Mooment.js解決了它。 我的解決方案使用Mooment.js http://momentjs.com/

+0

答案不應該要求不在問題或標記的庫。此外,答案應該實際上包含答案,而不是使用圖書館的建議。 – RobG

+0

@RobG。感謝您添加示例 – DININDU

1

輸入選擇框將位於瀏覽器的當前本地時區。提交時,它會將其轉換爲UTC。這通常是通過在服務器和數據庫中接受和存儲UTC時間來處理的。