$filter('date') returns 同一日期,无论时区如何
$filter('date') returns same date regardless on timezone
ctrl.time1 = $filter('date')(new Date(),"MMM dd yyyy - HH:mm:ss");
ctrl.time2 = $filter('date')(new Date(),"MMM dd yyyy - HH:mm:ss", "-06:00");
在页面上:
<div>ctrl.time1: {{::dateTimeCtrl.time1}}</div>
<div>ctrl.time2: {{::dateTimeCtrl.time2}}</div>
time1 = time2 = 2015 年 2 月 5 日 - 09:16:25
我想知道为什么?
不确定,但也许是这个?
来自AngularJS date filter documentation:
$filter('date')(date, format, timezone)
...
timezone
(optional): Timezone to be used for formatting. Right now, only 'UTC' is
supported. If not specified, the timezone of the browser will be used.
尝试以下方法如何:
$scope.time1 = $filter('date')(new Date(),"MMM dd yyyy - HH:mm:ss");
$scope.time2 = $filter('date')(new Date(),"MMM dd yyyy - HH:mm:ss -0600");
ctrl.time1 = $filter('date')(new Date(),"MMM dd yyyy - HH:mm:ss");
ctrl.time2 = $filter('date')(new Date(),"MMM dd yyyy - HH:mm:ss", "-06:00");
在页面上:
<div>ctrl.time1: {{::dateTimeCtrl.time1}}</div>
<div>ctrl.time2: {{::dateTimeCtrl.time2}}</div>
time1 = time2 = 2015 年 2 月 5 日 - 09:16:25
我想知道为什么?
不确定,但也许是这个?
来自AngularJS date filter documentation:
$filter('date')(date, format, timezone)
...
timezone
(optional): Timezone to be used for formatting. Right now, only 'UTC' is supported. If not specified, the timezone of the browser will be used.
尝试以下方法如何:
$scope.time1 = $filter('date')(new Date(),"MMM dd yyyy - HH:mm:ss");
$scope.time2 = $filter('date')(new Date(),"MMM dd yyyy - HH:mm:ss -0600");