date - 如何使用 Angular 8 中的 Bootstrap 4 在日期选择器中将日期格式转换为 DD MMM YYYY
问题描述
<div class="col-sm-8">
<i class="far fa-calendar-alt"></i>
<input
id="dtpFrom"
type="text"
placeholder="Datepicker"
placement="top"
class="form-control"
bsDatepicker
[bsConfig]="{dateInputFormat: 'DD MMM YYYY',containerClass: 'theme-blue'}"
[bsValue]="todayDate"
[minDate]="minDate"
[maxDate]="maxDate"
/>
</div>
import { BsDatepickerConfig } from'ngx-bootstrap/datepicker';
export class CardlessTransactionsComponent implements OnInit {
datePickerConfig: Partial<BsDatepickerConfig>;
privatetodayDate: Date = newDate();
minDate: Date;
maxDate: Date;
}
constructor(privatefb:FormBuilder) {
this.todayDate = newDate();
this.minDate = newDate();
this.maxDate = newDate();
this.minDate.setDate(this.minDate.getDate() - 7);
this.maxDate.setDate(this.maxDate.getDate() + 0);
在 HTML 文件中,我认为在 bsValue 中需要做一些事情,而在 ts 文件中,我不知道在哪里更改以获得我想要的输出,即显示月份名称而不是月份数字价值
解决方案
您应该通过 a 而不是在其外部获取今天的日期以formControl
使其正常工作...
相关的 HTML:
<div class="row">
<div class="col-sm-8">
<i class="far fa-calendar-alt"></i>
<input
id="dtpFrom"
placeholder="Datepicker"
placement="top"
class="form-control"
bsDatepicker
formControlName="dateMDY"
[bsConfig]="{dateInputFormat: 'DD MMM YYYY',containerClass: 'theme-blue'}"
[bsValue]="todayDate"
[minDate]="minDate"
[maxDate]="maxDate"
/>
</div>
</div>
在这里工作stackblitz
推荐阅读
- javascript - 按下 FlatList 项目时移动到另一个屏幕,截至目前我在 pressHandler() 中打印键值
- amazon-web-services - AWS网关无服务器{“消息”:“内部服务器错误”}
- node.js - Nodejs Redis hdel 不会删除密钥
- javascript - 关于 html/css/js 可折叠内容的问题
- fullcalendar - 是否可以调整全日历的宽度
- bash - 将功能分支合并到 master 以启用 git LFS (git) 后如何建议开发人员
- mysql - 在mysql中创建子查询
- arrays - 从 C 中的数组中消除 NaN 值
- docker - 通过参数化构建多个 Docker Hub
- arrays - 新数组,派生自另一个指向字符串的指针数组,只是顺序不同(在 C 中)