Angular Date pipe adds plus dot after year component

Viewed 1330

I'm using Angular version 2.4.5.

If I use the date pipe without any format it creates double dots after the year. If I use the pipe with the format: 'yyyyMM.dd.' it gives the correct date format

  • {{startDate | date}} => 2017..07.07.
  • {{startDate | date: 'yyyyMM.dd.'}} => 2017.07.07.

Which means that I can not set this as the value of a date input because it waits for the format yyyy-MM-dd and yyyy always have a plus dot that causes an error on input element. Neither of these work:

<input type="date" class="form-control" id="startDate" [ngModel]="currentItem.startDate | date: 'y-MM-dd'"
(ngModelChange)="currentItem.startDate = $event" name="startdate">

How can I solve this without using a new model with a correctly converted date string?

Update 2017-07-12: currentItem.startDate is a Date() object eg:

let currentItem.startDate = new Date();

The locale I'm trying to use is 'hu-HU' but the two dots were present without any locale provider. In that case the date pipe without any format strings gave the correct format for the input. (yyyy-MM-dd)

{{currentItem.startDate | date}}
0 Answers
Related