我不明白角度世界中的日期发生了什么
我创建了相同的日期,并试图以本地或UTC显示它们,但却得到了意想不到的结果
更新
是否可以创建一个以UTC为单位设置12小时的特定日期,并始终以UTC(非本地时区)显示
//template
<div ng-app ng-controller="MyCtrl">
<p>expecting date in local time {{date1}} </p>
<p>expecting date in local time along with time offset{{date1 | date:'yyyy-MM-dd hh:mm a Z' }} </p>
<p>expecting date in UTC time along with time offset{{date1 | date:'yyyy-MM-dd hh:mm a Z': 'UTC'}}</p>
<p>expecting date in local time {{date1 | date:'yyyy-MM-dd hh:mm a': 'UTC'}}</p>
<p>expecting time to be -10 hour from UTC {{date1 | date:'yyyy-MM-dd hh:mm a ': '-1000'}}</p>
<p>Expecting it to be in UTC: {{date2}}</p>
<p>Expecting it to be in UTC same as above {{date2 | date:'yyyy-MM-dd hh:mm a': 'UTC'}}</p>
<p>Expecting it to be -10 from UTC {{date2 | date:'yyyy-MM-dd hh:mm a': '-1000'}}</p>
<p>expecting it to be +12 from utc {{date4 |date:'yyyy-MM-dd hh:mm a': 'UTC'}}</p>
</div>
以下是我的控制器
// controller
function MyCtrl($scope, $filter) {
$scope.date1 = new Date("2017-12-13");
$scope.date2 = new Date(2017,11,13).toISOString();
$scope.date3 = new Date(2017,11,13);
$scope.date4= new Date($scope.date2).setHours(12)
console.log('date1',$scope.date1);
console.log('date2', $scope.date2);
console.log('date3', $scope.date3);
console.log('date4', $scope.date4);
console.log($filter('date')($scope.date2, 'medium'));
}
[小提琴] [1]