简体   繁体   English

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

[英]How to convert Date into Standard format

I am created a Laravel AngularJs application with a search bar;used to search data between two dates. 我创建了一个带有搜索栏的Laravel AngularJs应用程序;该应用程序用于搜索两个日期之间的数据。

I am created a AngularJs function in following way. 我通过以下方式创建了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);
        });
}

But,I got an error in data conversion.I need your help to convert AngularJs date into Universal format. 但是,我在数据转换中遇到错误。我需要您的帮助才能将AngularJs日期转换为通用格式。

I solved my problem in following ways: 我通过以下方式解决了我的问题:

 $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);
        });

}

Now the problem fixed.Thank you for your support for all. 现在问题已解决,谢谢大家的支持。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM