如何从 bootstrap 日期选择器中获取所选日期的值?

How to get the value of the selected date from bootstrap datepicker?

我正在使用 bootstrap 日期选择器来选择日期。

这是我的 html 代码

 <div>

<input  type="text" name="From" class="form-control" datepicker-popup="yyyy-MM-dd" ng-click="open($event)"  ng-model="Filters.Date" is-open="opened"  datepicker-options="dateOptions"  ng-required="true" close-text="X" />

</div>

我写了一个默认显示前一天日期的函数。但我无法获得选定的日期。如果我获得选定的日期值

,则会显示一些默认值,例如“1433077321717”

如何从日期选择器中获取所选日期?

Unix 时间戳以秒为单位。您可以将其转换为毫秒(通过将其乘以 1000)并将其传递给像这样的日期构造函数以将其转换为 Date 对象。

var unixtimestamp=1433077321717;
var selected=new Date(unixtimestamp*1000);

我认为 Bootstrap 正在返回时间戳。

根据您的意见。

您前一天为 select 编写了一个函数。今天(2015 年 6 月 1 日)是 2015 年 5 月 31 日。

你得到的输出是一个时间戳 新日期(时间戳)即新日期(1433077321717)= 2015 年 5 月 31 日星期日 18:32:01 GMT+0530(印度标准时间)即您设置的日期。

您获得的默认值是以毫秒为单位的时间戳。使用 angularjs 中提供的日期过滤器。

{{时间戳|日期:'short'}}。您可以按照以下 link 将时间戳转换为其他格式:

https://docs.angularjs.org/api/ng/filter/date

试试这个

var date = $filter('date')($scope.Filters.Date, "yyyy-MM-dd")

但首先将 $filter 添加到您的控制器

app.controller('Test',  function($scope, $filter,...){
}