如何在AngularJS格式化日期? [英] How to format date in AngularJS?

查看:87
本文介绍了如何在AngularJS格式化日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的问题。这是我的开始日期:

  $ scope.startDate = new Date(); 

我需要这个格式的2011-01-01T00:00:00中的日期。

解决方案

如建议使用$ filter内置服务,通过传入您的控制器:

  angular.module('app')
.controller('MyCtrl',['$ scope','MyService','$ filter'函数($ scope,MyService,$ filter){
$ scope.onSubmit = onSubmit;

函数OnSubmit(){
MyService.doSomethingSpecial($ filter('date' )($ scope.date,'dd / mm / yyyy')); //查看支持的格式
}

});


I have a simple issue. This is my startDate:

$scope.startDate = new Date();

I need the date in "2011-01-01T00:00:00" this format.

解决方案

As suggested use the $filter built-in service, by passing in to your controller:

angular.module('app')
       .controller('MyCtrl', ['$scope', 'MyService', '$filter', function($scope, MyService, $filter) {
            $scope.onSubmit = onSubmit;

            function OnSubmit() {
                MyService.doSomethingSpecial($filter('date')($scope.date, 'dd/mm/yyyy')); // see supported formats
            }

       });

这篇关于如何在AngularJS格式化日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆