0

I'm doing web app using Angular and WebAPI. I have a strange problem with difference dates between Angular Controller and WebAPI controller. On my html page i have a input for type of date:

 <input id="signupDateofBirth" ng-model="dateofBirth" placeholder="Date of birthday" type="date" max="1998-01-01" min="1900-12-31" class="form-control">

Let's assume that the date is 31.12.1990. I'm assigning it in my angular controller and while debugging date is correct: 31.12.1990 :

DateOfBirth: $scope.dateofBirth

DateOfBirth: Mon Dec 31 1990 00:00:00 GMT+01

enter image description here

The problem appears when i get object in WebAPI controller. The date is the day before to the date of Angular Controller. It's 30.12.1990 like on image: enter image description here

Any ideas? Maybe I need to format it?

1 Answer 1

1

This appears because of the timezone.

In your controller, date is correctly formatted with your local timezone (GMT+1).

When your API receive it, it doesn't know how to handle it: you have to specify that the dates returned in your JSON are in local timezone.

Try to specify your local timezone in your API startup.cs, e.g. with newtonsoft JSON :

json.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local;

EDIT

You should always pass an ISO formatted date to your API and vice versa. See : https://wikipedia.org/wiki/ISO_8601

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.