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

查看:68
本文介绍了如何在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

您可以在源代码中查看支持的日期格式日期过滤器.

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天全站免登陆