jQuery 角度js中的日期格式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17694041/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 19:45:42  来源:igfitidea点击:

Date format in angular js

javascriptjqueryangularjs

提问by Prashobh

I am displaying date in this format using angular

我正在使用 angular 以这种格式显示日期

{{ date }} ,date:\'MM-dd-yyyy HH:MM:ss\

how to display like Jan-dd-yyyyusing angular

如何像Jan-dd-yyyy使用angular一样显示

Is there any dirct way to do using angular js- (Using normal jquery i am able to do)

有没有什么直接的方法可以使用 angular js-(使用普通的 jquery 我可以做到)

回答by rppig

use Angular filter of date.

使用日期的角度过滤器。

{{date  | date:'MM-dd-yyyy HH:MM:ss'}}

See the following link.

请参阅以下链接。

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

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

回答by MADHAIYAN M

For custom date:

对于自定义日期:

$scope.user.dob = new Date('1980', '12' ,'10');  // controller code

 {{user.dob | date : 'MMM-dd-yyyy'}}  // Dec-10-1980

For current date:

对于当前日期:

 $scope.user.current= new Date();  // controller code

 {{user.current | date : 'MMM-dd-yyyy'}}  // Current date in given format

回答by Florian

Well,

好,

according to the docs, you have a builtin filter in angular, called date:

根据文档,您有一个内置的角度过滤器,称为date

<p>{{Date.now() | date:'yyyy'}}

would render to:

将呈现为:

<p>2013</p>

The yyyyin this case can be any format string documented. In the example you gave, this would be:

yyyy这种情况下可以记录任何格式字符串。在你给出的例子中,这将是:

{{date | date: 'MMM-dd-yyyy'}} # => "Jan-21-2013" (if date was a date object for this day)

回答by Amit

Try this

尝试这个

 {{ date }} ,date:\'MMM-dd-yyyy HH:MM:ss\