简体   繁体   English

如何在启动日期选择器中将startDate设置为月初?

[英]how to set startDate to beginning of the month in bootstrap datepicker?

I have two text field one for start date and one for end date. 我有两个文本字段,一个是开始日期,另一个是结束日期。 For start date i want to set beginning of the month as default. 对于开始日期,我想将月初设置为默认值。 But not getting how to accomplish that. 但没有得到如何实现这一目标。

This is my code 这是我的代码

<%= javascript_include_tag 'bootstrap-datepicker.js'%>

<%= form_tag '/mine', :class => "form-inline" do %>
 <%= label_tag 'start_date', 'Start Date' %>
 <%= text_field_tag 'start_date', nil, :class => 'calendar1' %>
 <%= label_tag 'end_date', 'End Date' %>
 <%= text_field_tag 'end_date', nil, :class => 'calendar' %>
<% end %>

<script>
$(".calendar").datepicker({format: "dd/mm/yyyy"});
$(".calendar1").datepicker({format: "dd/mm/yyyy"});
</script>

I tried like this by referring here 我通过引用这里尝试过

$(".calendar1").datepicker({format: "dd/mm/yyyy", startDate: Date.today.beginning_of_month});
or
$(".calendar1").datepicker({format: "dd/mm/yyyy",setDate date(Date.today.beginning_of_month)});

您可以这样:

<%= text_field_tag 'start_date', Date.today.beginning_of_month.strftime('%d/%m/%Y'), :class => 'calendar1' %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM