【发布时间】:2015-10-27 14:28:42
【问题描述】:
以下情况:
我有一个带有input[date] 字段的表单。我通过以下代码转换值:
$scope.entity.date = $filter('date')($scope.entity.date, 'yyyy-MM-dd');
这可以正确地将日期格式化为例如2015-10-27
当我使用$http.post 提交实体时,角度似乎将其识别为日期并将其重新格式化为2015-09-30T23:00:00.000Z。我在德国,我们有 GMT+1。所以角度将日期转换为格林尼治标准时间。
有什么办法可以禁用这种行为?
编辑:
HTML 代码:
<form ng-submit="submit()">
<input type="date" ng-model="entity.date" />
</form>
JS-代码:
$scope.submit = function() {
$scope.entity.date = $filter('date')($scope.entity.date, 'yyyy-MM-dd');
// when debugging this is the point where $scope.entity.date is 2015-10-27
// so it is the format and date I expect
$http({
data: $scope.entity,
method: POST,
url: '/resource'
})
.success(function(data) {
// do some stuff
});
// when looking into network traffic the request was sent with
// 2015-09-30T23:00:00.000Z as value for $scope.entity.date
};
【问题讨论】:
-
显示更多代码或尝试创建简单的 plunk 代表问题。 Angular 不太可能自行执行字符串->日期转换。
标签: angularjs angularjs-filter