0

I want date in dd-mmm-yyyy format..I'm getting as {dayOfYear: 106, dayOfMonth: 16, dayOfWeek: 2, era: 1, year: 2019, …}

I tried datepipe but its throwing error that 'Unable to convert "[object Object]" into a date' for pipe 'DatePipe'.

 item.executionDate=    this.datepipe.transform(item.executionDate , 'yyyy-MM-dd');
Priyanka
  • 370
  • 1
  • 6
  • 15
  • you need to convert your given object into a valid dateformat, after that you can format the date with the date pipe – yougeen Jun 13 '19 at 08:28
  • whatis the full format of {dayOfYear: 106, dayOfMonth: 16, dayOfWeek: 2, era: 1, year: 2019, …} – ysf Jun 13 '19 at 08:58
  • Yes I got the solution .. Now I'm doing it as let date = (item.executionDate.values[0] + "-" + item.executionDate.values[1] + "-" + item.executionDate.values[2]); item.startTime = this.datepipe.transform(new Date(date + " " + item.startTime + " " + "+0000"),"d MMM , y, h:mm:ss a"); item.endTime = this.datepipe.transform(new Date(date + " " + item.endTime + " " + "+0000"),"d MMM d, y, h:mm:ss a"); – Priyanka Jun 13 '19 at 09:45
  • @ysf Do you have any idea how to convert time from 00:00:01 to 8 min 49 second format ??? – Priyanka Jun 13 '19 at 09:46
  • you can do it with moment.js https://momentjs.com/docs/#/displaying/format/ – ysf Jun 13 '19 at 09:51
  • @ysf no is ther any way to do in angular – Priyanka Jun 13 '19 at 10:05
  • this problem is not specific to angular and there is no built-in way in angular. you can write your own pipe with custom logic to get such result. – ysf Jun 13 '19 at 11:56

0 Answers0