Angular5 + DotnetCore 2.1 - How to convert dateTime?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP

Angular5 + DotnetCore 2.1 - How to convert dateTime?



I have a problem handling date in angular, I got a datetime from server (using ASP.NET Core 2.1) like : "2018-07-29T06:31:41.57547" but actually I just need the date only without time like "2018-07-29". This caused my wont show the date in my form.



Should I use AutoMapper to map all datetime to string first or could I just convert to date in my angular ? or any other solutions ?





Did u try this from your api serverDate.ToString("yyyy-MM-dd");
– ershoaib
7 hours ago





I will convert in my api if it would be difficult to do with angular.
– nightingale2k1
6 hours ago





i strongly suggest u to use momentjs library to do stuffs like that
– Soroush_Neshat
11 mins ago




2 Answers
2



Just convert it in Angular using DatePipe



date: 'yyyy-MM-dd'


date: 'yyyy-MM-dd'



Or


<input name="startDate" type="date" formControlName="startDate" [ngModel]="startDate | date:'yyyy-MM-dd'" />





isn't pipe just for displaying data only ? I need to change the date itself to yyyy-mm-dd so I can put it into my formcontrol and it will be show up in <input type="date" formControlName="startDate"/>
– nightingale2k1
7 hours ago






It will display the date in the required format yyyy-mm-dd
– Wael Abbas
16 mins ago


yyyy-mm-dd



use momentjs library . u can convert it like this :


var convertedDate = moment(date).format('YYYY-MM-DD');






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

Executable numpy error

Trying to Print Gridster Items to PDF without overlapping contents

Mass disable jenkins jobs