我想得到值输入(文本)标签:dd / mm / yyyy并将此值转换为:mm / dd / yyyy并发送服务器。
答案 0 :(得分: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>