【问题标题】:Angular Material design date formatAngular Material 设计日期格式
【发布时间】:2015-05-07 13:49:12
【问题描述】:

我正在使用角度材料设计。 (https://material.angularjs.org/#/) 我有以下代码:

<md-input-container padding>
  <label>Some date</label>
  <input ng-model="searchQuery.SomeDate" type="date" name="invoiceDate" />
</md-input-container>

这给了我一个非常漂亮的带有日期选择器的文本框。用户可以手动输入日期或从日期选择器中选择日期。问题在于,基于 ui 文化,用户必须以 dd-MM-yyyy 格式或 MM-dd-yyyy 格式输入。

我不想要这个。我想强制使用 dd-MM-yyyy 格式。但我不知道该怎么做。你呢?

提前致谢!

【问题讨论】:

  • 你在尝试角度日期格式吗?
  • 试试这个:
  • 谢谢大家。所有建议都非常有帮助。

标签: javascript angularjs date


【解决方案1】:

如果您包含来自 i18n 的脚本,您可以直接将日期参数设置为您所在国家/地区的约定。

这是文件列表:https://code.angularjs.org/1.0.8/i18n/

然后一个简单的包含就可以了:

<script src="http://code.angularjs.org/1.0.8/i18n/angular-locale_XXXX.js"></script>

【讨论】:

    【解决方案2】:

    你想要这样的东西:

    用户看到 dd/MM/yyyy,但在程序中它是一个日期? 我是这样使用的:

     <span class="input-group">
       <input type="text" datepicker-popup="dd/MM/yyyy"  is-open="opened" close-text="Close"/>
       <span class="input-group-btn">
          <button type="button" class="btn btn-default" ng-click="open($event)">
          <i class="glyphicon glyphicon-calendar"></i></button>
       </span>
     </span>
    

    发送到模型的数据在dd/MM/yyyy之后格式化

    【讨论】:

    • 他使用有角度的材料,而不是有角度的 ui 引导程序。
    • @Apédémak 对不起,我的错误。但我仍然希望代码中有一些可以帮助的东西:)
    猜你喜欢
    • 1970-01-01
    • 2021-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多