Correct way to transfer dates from Angular to Web API 2

I have an Angular application that takes dates (date only not time) and sends them to the 2 REST web API service. We encounter a problem when someone from India uses the application due to problems with the time zone.

Currently, the Angular application converts the date in ISO8601 format to the UTC time zone and sends them to the Web API. When the data is received on the web API side, the date ends with an invalid one. If the form was added on 6/21/2016, the date ends as 6/20/2016. The desired solution is that the actual date value entered on the form is the date value received by the API.

One suggested solution is to process dates as strings instead of dates, and then just pass the date. It just seems like a hack to me and doesn't seem like the “right” way to do it.

What is the right way to deal with this situation?

Given the fact that the application has many date input inputs, is there an easy way to implement a solution for all input date values?

+4
source share
1 answer

The date format yyyy-MM-ddwill be adopted in the USA / India, so you can transfer it this way to your WebAPI. In JavaScript, before posting, you can change a date like this.

$scope.MyDate = $filter('date')($scope.MyDate, 'yyyy-MM-dd', timezone);

If you also want time, the format will be yyyy-MM-ddTHH:mmZ

0
source

All Articles