Reputation: 737
I'm trying to convert in angular a date from this format '2017-12-13T03:00:00Z[UTC]', to this format 'yyyy/MM/dd'. I got this code:
this.datepipe.transform(d.hour, 'yyyy-MM-dd HH:mm a z')
this.datepipe.transform(d.initDate, 'yyyy/MM/dd')
this.datepipe.transform(d.endDate, 'yyyy/MM/dd')
And in the browser i got this error:
ERROR Error: InvalidPipeArgument: '2017-12-13T03:00:00Z[UTC]' for pipe 'DatePipe'
at invalidPipeArgumentError (common.es5.js:2610)
at DatePipe.webpackJsonp.../../../common/@angular/common.es5.js.DatePipe.transform (common.es5.js:3506)
at discipinscripcion.component.ts:31
at Array.forEach (<anonymous>)
at DiscipinscripcionComponent.webpackJsonp.../../../../../src/app/components/discipinscripcion/discipinscripcion.component.ts.DiscipinscripcionComponent.inscribir (discipinscripcion.component.ts:29)
at Object.eval [as handleEvent] (DiscipinscripcionComponent.html:21)
at handleEvent (core.es5.js:11998)
at callWithDebugContext (core.es5.js:13467)
at Object.debugHandleEvent [as handleEvent] (core.es5.js:13055)
at dispatchEvent (core.es5.js:8614)
any tips on converting that kind of date format to yyyy/MM/dd? Thanks a lot!
Upvotes: 1
Views: 1972
Reputation: 46
You can try this :
datepipe = new DatePipe(en-US);
or to any other locale. Then return it as string
this.datepipe.transform(new Date(), 'yyyy/MM/dd');
Don't forget to import DatePipe
from @angular/common
and provide it in providers
array in your module (supposedly app.module.ts
.
Upvotes: 2