Angular 格式化日期,离子
Angular Format date, ionic
我正在使用 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){
});
您可以使用 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
});
}
}
我正在使用 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){
});
您可以使用 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
});
}
}