Witam,
Używam datepickera https://angular-ui.github.io/bootstrap/. Przykładowo wybieram 6 maja.
consol.log($scope.person.date) -> daje dobrą datę: Sat May 06 2017 0000 GMT+0200 (CEST).
A teraz to co wysyła przeglądarka w jsonie do serwera:
date:"2017-05-05"
Jak widać data jest przesunięta. Jak to naprawić, bo poźniej gdy odczytuje z bazy to wyświetla się 5 maj, zamiast 6.
0
0
no dobra a ten json to jakoś automagicznie się generuje?
0
Jest obiekt javy:
Car:
long id;
LocalDate date;
String name;
AngularJs
$scope.car = {};
HTML:
W formularzu piszę sobie:
$scope.car.date
$scope.car.name
Ustawienia kalendarza kontrolki:
$scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
$scope.format = $scope.formats[2];
$scope.open1 = function() {
$scope.popup1.opened = true;
};
$scope.popup1 = {
opened: false
};
<input type="text" class="form-control" uib-datepicker-popup="{{format}}" ng-model="newDoctor.dayOfBirth" is-open="popup1.opened" datepicker-options="dateOptions" ng-required="true" close-text="Close" alt-input-formats="altInputFormats" />
I teraz zapis do bazy angular:
Service
.add($scope.car)
.then(function (response) {
if (response.status == 200) {
$location.path("/doctors");
}
})
this.add = function (obj) {
return $http({
method: "POST",
url: '/api/save',
data: obj,
headers: {'Content-Type': 'application/json'}
}).then(function successCallback(response) {
return response;
}, function errorCallback(response) {
return response;
});
}