gpt4 book ai didi

javascript - 使用日期集的 AngularJS 日期选择器

转载 作者:行者123 更新时间:2023-12-02 14:18:34 24 4
gpt4 key购买 nike

我一直在尝试这个 AngularJS 包( https://www.npmjs.com/package/angularjs-datepicker )并且正在努力使用日期设置属性。在我的示例中,我有 2 个日历,1 个应显示昨天的日期,1 个应显示今天的日期。有人可以帮我设置这些日期吗?

日期选择器:

  <div class="datepicker-container">
<div class="date-from">
From:
<datepicker date-format="dd/MM/yyyy" selector="form-control" date-set="{{}}" 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-format="dd/MM/yyyy" selector="form-control" date-set="{{}}" 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>

设置日期:

$scope.dateFrom = new Date();
$scope.dateTo = new Date();

最佳答案

  var date = new Date();

$scope.today = date; //to show today's date

date.setDate(date.getDate() - 1); //to get yesterday's date, Ref:http://stackoverflow.com/questions/5511323/javascript-yesterday

$scope.yesterday = date;

使用日期设置:

从上面链接的文档中,https://www.npmjs.com/package/angularjs-datepicker 。我发现您必须将 date 对象作为 string 传递给属性 date-set ,因此将日期对象转换为字符串。

//js 
var date = new Date();

$scope.today = date.toString(); //to show today's date

date.setDate(date.getDate() - 1); //to get yesterday's date, Ref:http://stackoverflow.com/questions/5511323/javascript-yesterday

$scope.yesterday = date.toString();



//html
<datepicker date-format="dd/MM/yyyy" selector="form-control" date-set="{{today}}" class="date-picker">

<datepicker date-format="dd/MM/yyyy" selector="form-control" date-set="{{yesterday}}" class="date-picker">

关于javascript - 使用日期集的 AngularJS 日期选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38846276/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com