【问题标题】:Angular Format date, ionic角度格式日期,离子
【发布时间】:2015-05-27 17:13:12
【问题描述】:

我正在使用 ionicframework 构建具有 Angular 的混合应用程序。 我有一个带有两个输入框的表单:日期和时间。日期输入的值在数据库中保存为: Tue Mar 24 2015 00:00:00 GMT 0300 (AST) 在我的 android 设备上运行表单时,我得到了这种类型的数据,但我想将日期保存为简单的:24-04-2015

我尝试了什么

form.html

<form>
<input ng-model="app.date" class="positive" type="date">
<input ng-model="app.time" class="positive" type="time">
<button ng-click="makeApp(app)">send</button>
</form>

controller.js

$scope.makeApp = function (app) {
$http.post("http://www.foo.com/senddata.php?date="+app.date+"&time="+app.time)
.success(function(data){   
});

【问题讨论】:

    标签: angularjs html date time ionic-framework


    【解决方案1】:

    您可以使用 Angular 的日期过滤器:

    myApp.controller('MyController', ['$scope', '$http', '$filter', function ($scope, $http, $filter) {
    
        $scope.makeApp = function (app) {
    
            var appDate = $filter('date')(app.date, "dd/MM/yyyy");
            $http.post("http://www.foo.com/senddata.php?date="+appDate+"&time="+app.time)
                .success(function(data){   
                    // success
                });
        }
    }
    

    https://docs.angularjs.org/api/ng/filter/date

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-06
      • 1970-01-01
      • 1970-01-01
      • 2018-12-31
      • 2013-07-15
      相关资源
      最近更新 更多