Closed rvdhooft closed 7 years ago
I am hesitant to accept parseFormat. Instead you can pass a Date as your input, so that you don't need to worry about parse-format. As you know already, ngModel value doesn't have to be string.
Thanks for your response.
If I get a date string like
dateWithTimeStr = '2017-01-15T14:22:00-06:00';
and convert it to a Date
dateWithTime = moment(this.dateWithTimeStr, 'YYYY-MM-DDTHH:mm:ssZ').toDate();
logging the value shows Sun Jan 15 2017 15:22:00 GMT-0500 (Eastern Standard Time)
but when I open the datepicker it shows today's date, because in the component init the call to .getTime()
returns NaN for some reason, so it defaults to today.
Also, I would like to avoid converting to a Javascript Date object because I don't want to always show the local timezone.
Thanks for the explanation. Could you update README.md before I accept this PR?
Absolutely, should be all set. Let me know if there's anything else. Thanks.
I added the option to provide a parse format that is different from the date format. This is useful when passing in a date in a different format from the one that you want to display. For example, this allows the user to pass in a date string in ISO format but display it in
MM/DD/YYYY HH:mm z
format. I have added an example (ng2-utils-7) to your test app. WithoutparseFormat
, opening the datepicker shows an incorrect date; with parse-format, the datepicker shows the correct date, and after selecting a new date the input is formatted according to the givendateFormat
.