正确格式化日期以便在firefox中显示

Properly formatting date for display in firefox

本文关键字:firefox 显示 格式化 日期      更新时间:2023-09-26

我有这样的日期

美元范围。Newd = '2015-08-11 12:36:33.649';

来自后端JSON。在我的UI中,我想显示11/08/2015。

我使用Date.parse($scope.newd)转换,然后格式化。但这在FF中不起作用。我该怎么做呢?

为跨浏览器兼容性,

日期字符串用"-"转换为"/",去掉时间,

 $scope.oldDate = '2015-08-11 12:36:33.649';
 $scope.newD= $filter('date')(new Date($scope.oldDate.split(" ")[0].replace(/-/g,"/")), 'dd/MM/yyyy');

参考这个链接:http://dygraphs.com/date-formats.html

你可以像

    $scope.oldDate = '2015-08-11 12:36:33.649';
   $scope.newD= $filter('date')(new Date(parseInt($scope.oldDate.substr(6))), 'dd/MM/yyyy');

你必须在控制器中注入$filter

过滤器

在你的html中像这样使用日期过滤器

{{ date_expression | date : format : timezone}

阅读这里的文档

<标题> 例子

下面是一个日期输入的示例,它在通过过滤器后显示。

<p>
    <label>Select a date</label>
    <input type="date" id="date" ng-model="datevalue" />
</p>
<p> {{ datevalue | date : 'dd/MM/yyyy'}} </p>
   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();