我通过引导程序实现了这个日期选择器:
然后,我尝试更改日期,尽管我强制将代码的以下部分中所示的格式设置为“ dd / mm / yyyy”,但该日期会自动切换为月,反之亦然。
HTML:
public class CustomAdapter<T> extends ArrayAdapter<T> {
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(viewResourceId, null);
}
T customer = items.get(position);
if (customer != null) {
TextView customerNameLabel = (TextView) v;
if (customerNameLabel != null) {
customerNameLabel.setText(customer.toString());
}
}
return v;
}
@Override
public Filter getFilter() {
return nameFilter;
}
Filter nameFilter = new Filter() {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults filterResults = new FilterResults();
if (constraint != null) {
suggestions.clear();
T temp = null;
for (T customer : itemsAll) {
if (customer == null) {
continue;
}
String str1 = customer.toString().toLowerCase().trim().replaceAll(" ", "");
String str2 = constraint.toString().toLowerCase().trim().replaceAll(" ", "");
if (str1.contains(str2) || str1.startsWith(str2) || str2.contains(str1) || str2.startsWith(str1)) {
suggestions.add(customer);
temp = customer;
}
}
filterResults.values = suggestions;
filterResults.count = suggestions.size();
}
return filterResults;
}
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
items.clear();
notifyDataSetInvalidated();
if (results != null && results.count > 0) {
//setUpdatedList((ArrayList<T>) results.values);
if (results.count > 0) {
for (T o : (ArrayList<T>) results.values) {
items.add(o);
}
}
}
};
}
jQuery:
<div class="form-group" id="datainiziocpform">
<label for="datainizio">Data d'inizio:</label>
<div class="input-group date">
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
<input id="datainizio" type="text" class="form-control" name="datainizio" value="{{$data[0]->datainizio}}" />
</div>
</div>
答案 0 :(得分:1)
format:'dd/mm/yyyy',
尝试这样。
答案 1 :(得分:1)
尝试使用此format: "dd/mm/yyyy"
而非dateFormat: "dd/mm/yyyy"
$('#datainiziocpform .input-group.date').datepicker({
startDate:$('#datainizio').val(),
format: "dd/mm/yyyy",
autoclose:true,
language: "it"
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" >
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/css/bootstrap-datepicker.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.8.0/js/bootstrap-datepicker.js"></script>
<div class="form-group" id="datainiziocpform">
<label for="datainizio">Data d'inizio:</label>
<div class="input-group date">
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
<input id="datainizio" type="text" class="form-control" name="datainizio" />
</div>
</div>