角度/ javascript html输入类型'时间'显示错误提交时间

问题描述:

我正面临着一个奇怪的问题。角度/ 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

似乎你有问题和时区。这个问题也有我。我用Mooment.js解决了它。 我的解决方案使用Mooment.js http://momentjs.com/

+0

答案不应该要求不在问题或标记的库。此外,答案应该实际上包含答案,而不是使用图书馆的建议。 – RobG

+0

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

输入选择框将位于浏览器的当前本地时区。提交时,它会将其转换为UTC。这通常是通过在服务器和数据库中接受和存储UTC时间来处理的。