如何将日期转换为标准格式

How to convert Date into Standard format

本文关键字:标准 格式 转换 日期      更新时间:2023-09-26

我创建了一个带有搜索栏的Laravel-AngularJs应用程序;用于搜索两个日期之间的数据。

我以以下方式创建了一个AngularJs函数。

$scope.searchDateParticular=function()
{
    if( $scope.fromDate.toISOString)
        $scope.fromDate = $scope.fromDate.toISOString();
    if( $scope.toDate.toISOString)
        $scope.toDate = $scope.toDate.toISOString();
    $http.get('/api/accountParticularWithDate',{account_id:$scope.myAccount.id,fromDate:$scope.fromDate,toDate:$scope.toDate}).
        success(function(data,status,headers,config){
            $scope.particulars=data;
            console.log(data);
        }).error(function(data,status,headers,config){
            console.log(data);
        });
}

但是,我在数据转换中出错了。我需要你的帮助把AngularJs的日期转换成通用格式。

我通过以下方式解决了问题:

 $scope.searchDateParticular=function(fromDate,toDate)
{
    var from = $filter("date")(Date.parse(fromDate), 'yyyy-MM-dd');
    var to = $filter("date")(Date.parse(toDate), 'yyyy-MM-dd');
    $http.get('/api/accountParticularWithDate',{params:{'account_id':$scope.myAccount.id,'fromDate':to,'toDate':from}})
        .then(function(response){
            $scope.particulars=response.data;
            getTotalStatement($scope.particulars);
            //console.log(response.data);
        });
}

现在问题解决了。感谢大家的支持。