【问题标题】:Angular-Material: Native DateTime Picker Component , No SecondsAngular-Material:本机日期时间选择器组件,无秒
【发布时间】:2021-06-01 13:27:53
【问题描述】:

如何制作这个日期时间选择器,而不是显示秒数?并且只显示日期、小时和分钟?

目前它还有几秒钟,

  <mat-form-field appearance="outline" floatLabel="always">
    <mat-label>Start Date</mat-label>
    <input 
      matInput
      type="datetime-local" 
      placeholder="Start Date"
    >
  </mat-form-field>

我只想使用原生html,https://stackoverflow.com/a/54889140/15293929 没有 npm 包

【问题讨论】:

    标签: angular typescript datepicker datetimepicker angular10


    【解决方案1】:

    我认为您可以为此使用本机日期选择器

    您的代码 sn-p 将如下所示:

    <mat-form-field appearance="outline" floatLabel="always">
        <mat-label>Start Date</mat-label>
        <input 
          matInput
          type="date" // Only shows the datepicker interface
          placeholder="Start Date"
        >
      </mat-form-field>
    

    参考:https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date

    【讨论】:

    • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接答案可能会失效。 - From Review
    • 根据您的反馈更新了我的答案
    • 我指出了你的答案并给了分数,也请随意竖起大拇指,谢谢
    【解决方案2】:

    确保你修改了 date 的值,将 Seconds 和 Milliseconds 设置为 0。那么 datepicker 中的 seconds 菜单选项将不会显示。

    newDate.setSeconds(0);
    newDate.setMilliseconds(0);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-14
      • 2020-08-22
      • 1970-01-01
      • 2018-06-09
      相关资源
      最近更新 更多