2016-08-09 17 views
0

Ich habe vor kurzem eine Datumsauswahl mit moment.js implementiert. Aus irgendeinem Grund zeigt es das falsche Datum an. Ich habe das Datum außerhalb der Datumsauswahl angezeigt und es war in Ordnung. Ich console.logged die Variablen, um zu sehen, was gespeichert wurde und das stellte sich heraus, dass das Format, das ich wollte. Wenn ich jedoch die Daten in der Datumsauswahl aufruft, wird sie im falschen Format angezeigt. Es sollte genau das gleiche sein, was unter der Datumsauswahl ausgegeben wird. Kann mir jemand erklären, wo ich falsch liege?Datumsauswahl wird in 2 verschiedenen Daten angezeigt

Datumsauswahl und richtige Datum unterhalb ausgegeben werden:

enter image description here

<div class="datepicker-container"> 
     <div class="date-from"> 
      From: 
      <datepicker date-set="{{yesterday}}" selector="form-control" date-max-limit="{{today}}" class="date-picker"> 
      <div class="input-group"> 
       <input class="form-control" placeholder="Choose a date"/> 
       <span class="input-group-addon" style="cursor: pointer"> 
       <i class="glyphicon glyphicon-calendar"></i> 
       </span> 
      </div> 
      </datepicker> 
     </div> 
     <div class="date-too"> 
      To: 
      <datepicker date-set="{{today}}" selector="form-control" date-min-limit="{{yesterday}}" class="date-picker"> 
      <div class="input-group"> 
       <input class="form-control" placeholder="Choose a date"/> 
       <span class="input-group-addon" style="cursor: pointer"> 
       <i class="glyphicon glyphicon-calendar"></i> 
       </span> 
      </div> 
      </datepicker> 
     </div> 
     </div> 
     <h4>{{yesterday}} and {{today}}</h4> 

definieren Datum:

enter image description here

var currentDate = moment(new Date()).format("DD/MM/YYYY"); 
console.log("1", currentDate); 

$scope.today = currentDate.toString(); 
console.log("2", $scope.today); 

var yesterdaysDate = moment(new Date()).subtract(1, 'days').format("DD/MM/YYYY"); 
console.log("3", yesterdaysDate); 

$scope.yesterday = yesterdaysDate.toString(); 
console.log("4", $scope.yesterday); 
+1

Könnten Sie die 'datepicker' Richtlinie/Komponentendeklaration zur Verfügung stellen? –

Antwort

0

Gelöst, formatierte ich das Datum mit der Datumsauswahl statt Moment.

Datumsauswahl:

<div class="datepicker-container"> 
    <div class="date-from"> 
     From: 
     <datepicker date-set="{{yesterday}}" date-format="dd/MM/yyyy" selector="form-control" date-max-limit="{{today}}" class="date-picker"> 
     <div class="input-group"> 
      <input class="form-control" placeholder="Choose a date"/> 
      <span class="input-group-addon" style="cursor: pointer"> 
      <i class="glyphicon glyphicon-calendar"></i> 
      </span> 
     </div> 
     </datepicker> 
    </div> 
    <div class="date-too"> 
     To: 
     <datepicker date-set="{{today}}" date-format="dd/MM/yyyy" selector="form-control" date-min-limit="{{yesterday}}" class="date-picker"> 
     <div class="input-group"> 
      <input class="form-control" placeholder="Choose a date"/> 
      <span class="input-group-addon" style="cursor: pointer"> 
      <i class="glyphicon glyphicon-calendar"></i> 
      </span> 
     </div> 
     </datepicker> 
    </div> 
    </div> 
    <h4>{{yesterday}} and {{today}}</h4> 

Moment:

var currentDate = moment(new Date()); 
console.log("1", currentDate); 

$scope.today = currentDate.toString(); 
console.log("2", $scope.today); 

var yesterdaysDate = moment(new Date()).subtract(1, 'days'); 
console.log("3", yesterdaysDate); 

$scope.yesterday = yesterdaysDate.toString(); 
console.log("4", $scope.yesterday); 
Verwandte Themen