2016-08-17 47 views
1

我正在使用bootstrap-datepaginator Source在bootstrap日期分页程序中获取所选日期

下面的代码以这种格式而不是我想用此格式返回它Sun Aug 14 2016 00:00:00 GMT+0400

返回日期14/Aug/2016

<script> 
 
     $(document).ready(function() { 
 
      var options = { 
 
       selectedDate: '2016-01-01', 
 
       selectedDateFormat: 'YYYY-MM-DD' 
 
      } 
 

 
      $('#paginator').datepaginator(options); 
 

 
      $('#paginator').datepaginator(); 
 

 
      $('#paginator').on('selectedDateChanged', function (event, date) { 
 
       // Your logic goes here 
 
       alert(date); 
 
      }); 
 
     });</script>

回答

1

试试这个

var months = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", 
       "Jul", "Aug", "Sep", "Oct", "Ntove", "Dec" ]; 


var dati = "Sun Aug 14 2016 00:00:00 GMT+0400"; 


var date = new Date(dati); 
var thedate = date.getDate(); 
var themonth = date.getMonth(); 
var theyear = date.getFullYear(); 

alert(thedate); 
alert(themonth); 
alert(theyear); 

var newdate = thedate +"/"+months[themonth]+"/"+theyear; 
alert(newdate); 

工作示例

<html> 
 
<head></head> 
 
<title></title> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
 
<body> 
 

 

 

 
</body> 
 

 
<script type="text/javascript"> 
 

 
var months = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", 
 
       "Jul", "Aug", "Sep", "Oct", "Ntove", "Dec" ]; 
 

 

 
var dati = "Sun Aug 14 2016 00:00:00 GMT+0400"; 
 

 

 
var date = new Date(dati); 
 
var thedate = date.getDate(); 
 
var themonth = date.getMonth(); 
 
var theyear = date.getFullYear(); 
 

 
alert(thedate); 
 
alert(themonth); 
 
alert(theyear); 
 

 
var newdate = thedate +"/"+months[themonth]+"/"+theyear; 
 
alert(newdate); 
 

 

 

 

 

 

 

 
</script> 
 

 
</html>