我有约会日期
$ scope.newd ='2015-08-11 12:36:33.649';
来自后端JSON。在我的UI中,我希望显示为2015年8月11日。
我使用Date.parse($scope.newd)
进行转换然后格式化。但这在FF中不起作用。我该怎么做?
答案 0 :(得分:1)
您可以在控制器层上应用过滤器,如
$scope.oldDate = '2015-08-11 12:36:33.649';
$scope.newD= $filter('date')(new Date(parseInt($scope.oldDate.substr(6))), 'dd/MM/yyyy');
您必须在控制器中注入$ filter。
答案 1 :(得分:1)
日期字符串转换为" - "到" /"消除时间,
$scope.oldDate = '2015-08-11 12:36:33.649';
$scope.newD= $filter('date')(new Date($scope.oldDate.split(" ")[0].replace(/-/g,"/")), 'dd/MM/yyyy');
答案 2 :(得分:0)
在html中使用日期过滤器
{{ date_expression | date : format : timezone}
阅读文档here。
以下是通过过滤器后显示的日期输入示例。
<p>
<label>Select a date</label>
<input type="date" id="date" ng-model="datevalue" />
</p>
<p> {{ datevalue | date : 'dd/MM/yyyy'}} </p>
答案 3 :(得分:-1)
Date.prototype.today = function () {
return ((this.getDate() < 10)?"0":"") + this.getDate() +"/"+(((this.getMonth()+1) < 10)?"0":"") + (this.getMonth()+1) +"/"+ this.getFullYear();
}
var newDate = new Date($scope.newd );
var date =newDate.today();
$scope.newd = newDate.today();