我在输入元素上使用Bootstrap的Datepicker,并且想知道 - 有没有办法以不同的格式显示日期,我可以如何设置日期或从输入元素获取日期?我的数据源以yyyymmdd
格式显示日期,但我想在输入元素中将日期显示为mm/dd/yyyy
。例如:
20150721
。07/21/2015
。07/28/2015
。20150728
。有没有办法使用Bootstrap的datepicker执行此格式映射?提前谢谢!
答案 0 :(得分:0)
根据source,只需设置格式属性。
Internal Server Error: /api/v1/users/
Traceback (most recent call last):
File "/Users/test/virtualenvs/app/lib/python2.7/site-packages/django/core/handlers/base.py", line 223, in get_response
response = middleware_method(request, response)
File "/Users/test/virtualenvs/app/lib/python2.7/site-packages/django/middleware/clickjacking.py", line 31, in process_response
if response.get('X-Frame-Options', None) is not None:
AttributeError: 'Response' object has no attribute 'get'
[21/Jul/2015 06:44:55]"POST /api/v1/users/ HTTP/1.1" 500 69466
答案 1 :(得分:0)
也许这是你的解决方案:
var _date = '20150721';
$('#_date').datepicker({
autoclose: true,
clearBtn: true,
format: 'mm/dd/yyyy'
});
$('#_date').datepicker('setDate', _date);
$('#_test').click(function () {
alert($('#_date').val());
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.0/css/bootstrap-datepicker.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.0/js/bootstrap-datepicker.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/2.3.2/js/bootstrap.js"></script>
<input id='_date'><button id='_test'>Test</button>
&#13;