簡體   English   中英

如何將日期轉換為標准格式

[英]How to convert Date into Standard format

我創建了一個帶有搜索欄的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);
        });

}

現在問題已解決,謝謝大家的支持。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM