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

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

问题描述

我想格式化日期为 mm / dd / yyyy 。我试过以下,没有一个对我有用。
任何人都可以帮助我吗?

I want to format date as mm/dd/yyyy. I tried the following and none of it works for me. Can anyone help me with this?

参考: ui-date

<input ui-date ui-date-format="mm/dd/yyyy" ng-model="valueofdate" /> 

<input type="date" ng-model="valueofdate" />


推荐答案

Angular.js有一个内置的日期过滤器。

Angular.js has a built-in date filter.

演示

// in your controller:
$scope.date = '20140313T00:00:00';

// in your view, date property, filtered with date filter and format 'MM/dd/yyyy'
<p ng-bind="date | date:'MM/dd/yyyy'"></p>

// produces
03/13/2014

你可以在日期过滤器的源中查看支持的日期格式 / a>。

You can see the supported date formats in the source for the date filter.

编辑

如果你想获得datepicker中的正确格式(如果您使用的是datepicker或仅使用它的格式化程序,则不清楚),那些支持的格式字符串在这里: https://api.jqueryui.com/datepicker/

If you're trying to get the correct format in the datepicker (not clear if you're using datepicker or just trying to use it's formatter), those supported format strings are here: https://api.jqueryui.com/datepicker/

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

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