我想获取值输入(文本)标签:dd/mm/yyyy 并将此值转换为:mm/dd/yyyy 并发送服务器。
问问题
1248 次
1 回答
0
您可以使用方法获取所选日期date
,然后使用矩format
函数转换格式,将日期转换为您需要的格式。我建议编辑您的问题并添加一些代码以获得更准确的答案,无论如何以下示例可以帮助您完成工作:
$(function () {
// Init Eonasdan datetimepicker
$('#datetimepicker1').datetimepicker({format: 'DD-MM-YYYY'});
$('#btnSend').click(function(){
// Get selected date (moment object)
var myDate = $('#datetimepicker1').data("DateTimePicker").date();
if( myDate != null ){
// Convert moment date to string chosing format
var dateStringForServer = myDate.format('MM-DD-YYYY');
alert('send: '+dateStringForServer);
}
});
});
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.css" rel="stylesheet"/>
<link href="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/css/bootstrap-datetimepicker.css" rel="stylesheet"/>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.13.0/moment.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/js/bootstrap.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.7.14/js/bootstrap-datetimepicker.min.js"></script>
<div class='input-group date' id='datetimepicker1'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
<button id="btnSend" class="btn btn-primary">Send</button>
于 2016-05-20T08:22:34.407 回答