如何在AngularJs中从日期和时间创建日期时间?

时间:2017-09-16 10:18:46

标签: angularjs

我正在与AngularJs合作开展一个项目。 这里我有3个html控件。

  • datepicker(html5' s 日期)=> $scope.date
  • timepicker(html5' s 时间)=> $scope.from
  • timepicker(html5' s 时间)=> $scope.to

下面是html代码。

<form>
  <div class="form-group row">
    <label for="" class="col-sm-2 col-form-label">Set date</label>
    <div class="col-sm-5">
      <!-- <input type="email" class="form-control" id="inputEmail3" placeholder="Email"> -->
      <datepicker date-format="yyyy-MM-dd" selector="form-control">
        <div class="input-group">
          <input class="form-control" placeholder="Choose a date" ng-model="date" id="date" />
          <spam class="input-group-addon" style="cursor: pointer">
            <i class="fa fa-lg fa-calendar"></i>
          </spam>
        </div>
      </datepicker>
    </div>
  </div>
  <div class="form-group row">
    <label for="" class="col-sm-2 col-form-label">Set time</label>
    <div class="col-sm-4">
      <input type="time" class="form-control" placeholder="From" ng-model="from" id="from">
    </div>
    <label for="" class="col-sm-1 col-form-label">To</label>
    <div class="col-sm-4">
      <input type="time" class="form-control" placeholder="To" ng-model="to" id="to">
    </div>
  </div>
</form>

现在进行服务电话我需要通过日期时间,但此处我分别有日期时间

如何从以上可用数据构建日期时间和日期时间?

1 个答案:

答案 0 :(得分:0)

您可以在控制器中的功能中组合日期。首先使用Date.prototype.toISOString()方法格式化日期/时间,然后使用String.prototype.substring()方法分别取dateParttimePart,最后合并两者以创建新{ {1}}实例。

Date