如何从实现日期选择器中获取选定的日期?

这是我的输入:

<div class="input-field col s3">
   <input id="buyDate" class="datepicker" type="text" name="buyDate"
   ng-model="buyDate" materialize-date-picker readonly>
</div>


而我的脚本:

$scope.SaveButton = function(){
      var postRequest = $http({
          method: "POST",
          url: "http://localhost:5000/licenses",
          dataType: 'json',
          data : {
             name: $scope.name,
             count: $scope.count,
             buyDate: $scope.buyDate,
             licenseType: $scope.licenseType.licenseTypeId
          },
          headers: { "Content-Type": "application/json"}
      });

      postRequest.error(function (data, status){
          $window.aler(data.Message);
      })
  }

最佳答案

我不知道这是否正是您要的东西,但是您可以

var dateStr = document.getElementById("buyDate").value;
var dateObj = Date.parse(dateStr);


然后dateObj将是对应于该日期的datetime对象。我不知道Angular,所以熟悉它的人也许可以为您提供一个更加Angular-y的答案,但是就js而言,这应该可以工作。

07-24 09:31