Date is returning one day less when using REST Api
<!doctype html>
<html ng-app="ui.bootstrap.demo">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular.js"></script>
<script src="https://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-1.3.3.js"></script>
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.5/angular-animate.js"></script>
<style>
.registration-form .form-control{
border-radius:2px;
}
.registration-form .has-error .form-control, .registration-form .has-error .form-control:hover, .registration-form .has-error .form-control:active{
border-color: red;
box-shadow: none !important;
}
.has-error input[type="text"]:focus,
.has-error input[type="password"]:focus,
.has-error input[type="number"]:focus{
background-color: red !important;
}
.registration-form label{
font-weight: normal;
}
.registration-form .form-group input[type="text"]:focus,
.registration-form .form-group input[type="password"]:focus,
.registration-form .form-group input[type="number"]:focus{
outline: none;
box-shadow:none !important;
background-color:#18b6d6;
}
.error_message_text{
color:red;
}
.glyphicon{
vertical-align: bottom;
float: right;}
.dob-select-container{
margin: 0px;
padding: 0px;
}
.dob-select-container .dd .ddTitle .ddTitleText {
width: 100%;
}
.styled-select {
display: inline-block;
height: 33px;
margin-right: 10px;
}
.styled-select .ddcommon {
width: 78px !important;
}
</style>
<script>
angular.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('DatepickerPopupDemoCtrl', function ($scope) {
$scope.today = function() {
$scope.dt = new Date();
};
//$scope.today();
$scope.dt = new Date();
$scope.clear = function() {
$scope.dt = null;
};
$scope.inlineOptions = {
customClass: getDayClass,
// minDate: new Date(),
showWeeks: true
};
$scope.dateOptions = {
dateDisabled: disabled,
formatYear: 'yy',
startingDay: 1
};
// Disable weekend selection
function disabled(data) {
var date = data.date,
mode = data.mode;
return mode === 'day' && (date.getDay() === 0 || date.getDay() === 6);
}
$scope.toggleMin = function() {
var date = new Date();
date.setDate((new Date()).getDate() - 30);
$scope.dateOptions.minDate = date;
};
$scope.toggleMin();
$scope.setMin = function() {
var date = new Date($scope.dt);
alert("gg");
date.setDate((date).getDate() - 30);
$scope.dateOptions.minDate = date;
};
var date1 = new Date();
date1.setDate((new Date()).getDate() + 30);
$scope.dateOptions.maxDate = date1;
$scope.open1 = function() {
$scope.popup1.opened = true;
};
$scope.open2 = function() {
$scope.popup2.opened = true;
};
$scope.setDate = function(year, month, day) {
$scope.dt = new Date(year, month, day);
};
$scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate','dd/MM/yyyy'];
$scope.format = $scope.formats[0];
//$scope.altInputFormats = ['M!/d!/yyyy'];
$scope.popup1 = {
opened: false
};
$scope.popup2 = {
opened: false
};
var tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
var afterTomorrow = new Date();
afterTomorrow.setDate(tomorrow.getDate() + 1);
$scope.events = [
{
date: tomorrow,
status: 'full'
},
{
date: afterTomorrow,
status: 'partially'
}
];
function getDayClass(data) {
var date = data.date,
mode = data.mode;
if (mode === 'day') {
var dayToCheck = new Date(date).setHours(0,0,0,0);
for (var i = 0; i < $scope.events.length; i++) {
var currentDay = new Date($scope.events[i].date).setHours(0,0,0,0);
if (dayToCheck === currentDay) {
return $scope.events[i].status;
}
}
}
return '';
}
});
</script>
</head>
<body>
<div class="container registration-form">
<form name="memberForm" class="form-inline" novalidate>
<div ng-controller="DatepickerPopupDemoCtrl">
<h4>Popup</h4>
<div class="form-group" ng-class="{ 'has-error' : memberForm.dateOfBirth.$invalid && (memberForm.dateOfBirth.$touched || memberForm.$submitted) }">
<label for="Date of Birth" class="" ng-hide="memberForm.dateOfBirth.$invalid && (memberForm.dateOfBirth.$touched || memberForm.$submitted)">Date of Birth(dd/mm/yyyy)*</label>
<label class="error_message_text" ng-show="memberForm.dateOfBirth.$invalid && (memberForm.dateOfBirth.$touched || memberForm.$submitted)"> Date of birth is required </label>
<p class="input-group" style="width:270px;" >
<input type="text" class="form-control" name="dateOfBirth"
uib-datepicker-popup="MM/dd/yyyy" ng-model="dt"
is-open="popup1.opened" datepicker-options="dateOptions"
min-date="minDate" max-date="maxDate"
ng-required="true" close-text="Close" alt-input-formats="altInputFormats" ng-change="setMin()" ng-readonly="true"/>
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="open1()"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
</p>
</div>
<button type="submit" class="btn btn-blue-1">Submit</button>
</form>
</div>
</body>
</html>
No comments:
Post a Comment