Angular Datepicker更改日期格式 [英] Angular Datepicker change dateformat
本文介绍了Angular Datepicker更改日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Angular Material中的DatePicker,我想将输出格式更改为 yyyy / mm / dd
。
i use the DatePicker from Angular Material and I would like to change the output format to yyyy/mm/dd
.
当前它以以下格式打印日期: 2018年11月14日星期三00:00:00 GMT + 0100(欧洲中部正常时间)
Currently it prints the date in the following format: Wed Nov 14 2018 00:00:00 GMT+0100 (Central European Normal Time)
我该怎么做?
datepicker = new FormControl('', [Validators.required]);
console.log(this.datepicker.value.toString());
推荐答案
您可以使用 Moment.js 将日期格式设置为 YYYY / MM / DD格式
You can use Moment.js to format your date to "YYYY/MM/DD" format
moment(this.datepicker.value).format('YYYY/MM/DD')
使用时间会帮助我们将日期更改为不同的格式
using moment will help us change date into different formats
这篇关于Angular Datepicker更改日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文