1

I have an app where the user can input some dates.

After some research I decided to use mydatepicker v2.0.31

The issue is that when I choose a date in the frontend and send it to the backend, as the backend app a java app) is in a different timezone that the regular users, it change the date for the day before.

I tried several things... What I'm doing now is converting the date in the angular app to string with the format yyyy-mm-dd before sending it to the backend, but then the results (after the backend process the date) is one day less.. As I'm in ART and the backend in EST... Is there any option I can send a date without assuming the Time Zone?

1 Answer 1

1

IMHO, the only sane way to deal with dates between a client and a server is to explicitly state the time zone. ISO-8601 time format is built for this.

Again, IMHO, the only sane thing to do is to always use specify the date/time in UTC.

When you do that, the time zone is specified as 'Z' (for 'Zulu' time, military terminology for UTC), as in: "2017-11-05T20:41:06+00:00", the approximate time of this post, which for me is 3:41PM on Nov. 5, 2017 EST., EST being 5 hours behind UTC.

Note that in JavaScript (or Typescript), the Date object has a toISOString() method that will produce an ISO-8601 compliant date string, as will JSON.stringify(). So, if you send an object from Angular to your back-end via Angular's HTTPClient, and Dates in the that object should automatically be sent in ISO-8601 format.

If you are converting to strings first, don't. Leave them as Dates, and let JSON.stringify() convert them when you send the object to the back-end via HttpClient.

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.