Issue
I'm trying to send a datetime from angular app to the ASP.NET Core web API via post call, but after sending the correct date the API receives a time that is 6 hours behind than the time has sent.
this.subject.StartTime = form.value.startTime ? moment(today + ' ' + form.value.startTime) : '';
this.subject.EndTime = form.value.endTime ? moment(today + ' ' + form.value.endTime).toDate() : '';
Angular sent's Wed Sep 25 2019 22:00:00 GMT+0600
Why it's happening, do I have to set my culture in my ASP.NET Core app? but my client and server in same timezone.
Is there any way to set my default Timezone in the asp.net core? as we set DefaultRequestCulture.
Solution
The Date from the server is a UTC Date, so I had to convert the date object to a local DateTime object in the front-end like below.
var date = new Date(dateString).toString() + 'Z';
in some places I saw only using new Date(dateString) works fine but in my case, I had to add +'Z' at end of dateString, It's a UTC Date String.
Answered By - Sabir Hossain

0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.