如何在 eonasdan bootstrap datetimepicker 中获取值 dd/mm/yyyy 到 mm/dd/yyyy
How to get value dd/mm/yyyy to mm/dd/yyyy in eonasdan bootstrap datetimepicker
我想获取值输入(文本)标签:dd/mm/yyyy 并将此值转换为:mm/dd/yyyy 并发送服务器。
您可以使用date
method and then convert format using moment 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>
我想获取值输入(文本)标签:dd/mm/yyyy 并将此值转换为:mm/dd/yyyy 并发送服务器。
您可以使用date
method and then convert format using moment 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>