When I select a date from the datepicker input field, it is being incorrectly saved in the database.
I am selecting the date using the datepicker and then using AngularJS to send it to Spring MVC
AngularJS:
$scope.updateProjectDetails = function(detail) {
$http.post('${pageContext.request.contextPath}/api/details', detail)
.then(function(response) {
console.log(response)
});
}
Chrome Console:
config: {method: "POST", transformRequest: Array(1), transformResponse: Array(1), paramSerializer: ƒ, url: "/editor-application/api/details", …}
data:
date: 1557439200000
hours: 2
id: 76
projectId: 53
1557439200000 -> 5/10/2019, 12:00:00 AM
Then the JSON is posted to the MVC mechanism:
Controller:
@PostMapping(path = "/details")
public ProjectDetails updateProjectDetails(@RequestBody ProjectDetails details) {
details.setId(0);
editorService.updateProjectDetails(details);
return details;
}
DAO:
@Override
@Transactional
public void updateProjectDetails(ProjectDetails details) {
Session currentSession = sessionFactory.getCurrentSession();
currentSession.saveOrUpdate(details);
}
And in the database:
76 2019-05-09 2 53
The date always appears to be one day behind. I understand there may be a timezone issue, but how can I resolve it?