Javascript 如何在angular js中将日期格式化为DD/MM/YYYY

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27734037/
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-23 00:35:01  来源:igfitidea点击:

How to format date into DD/MM/YYYY in angular js

javascriptangularjs

提问by query

In my database i am storing date in this format 2015-12-14 00:00:00(yy/mm/dd h:m:s).How can i convert this date into this format 14 dec 2015 in angularjs ?Here is the format of my angular data:

在我的数据库中,我以这种格式存储日期 2015-12-14 00:00:00(yy/mm/dd h:m:s)。如何在 angularjs 中将此日期转换为 2015 年 12 月 14 日的格式?这里是我的角度数据的格式:

{{data.time_stamp}}

回答by manuelbcd

First, store mysql date in a jscript date object:

首先,将 mysql 日期存储在一个 jscript 日期对象中:

var aux = "2015-12-14 00:00:00".split(/[- :]/);
var vdate = new Date(aux[0], aux[1]-1, aux[2], aux[3], aux[4], aux[5]);

Then, Angular code is quite simple and documented, for example:

然后,Angular 代码非常简单并且有文档记录,例如:

{{vdate | date:'dd MMM yyyy'}}

Check official information here: https://docs.angularjs.org/api/ng/filter/date

在此处查看官方信息:https: //docs.angularjs.org/api/ng/filter/date

Regards

问候

回答by lwalden

Use Angular's built in filter for dates. https://docs.angularjs.org/api/ng/filter/date

使用 Angular 内置的日期过滤器。https://docs.angularjs.org/api/ng/filter/date

{{ date_expression | date : format : shortDate}}