繁体   English   中英

更改日期选择器的日期格式

[英]change date format of datepicker

我创建与ASP.NET angularJS一个web应用程序,这是我的一个JavaScript的datepicker

$('#sandbox-container input').datepicker({
  autoclose: true
});
$('#sandbox-container input').on('show', function (e) {
  console.debug('show', e.date, $(this).data('stickyDate'));
  if (e.date) {
    $(this).data('stickyDate', e.date);
  } else {
    $(this).data('stickyDate', null);
  }
});
$('#sandbox-container input').on('hide', function (e) {
  console.debug('hide', e.date, $(this).data('stickyDate'));
  var stickyDate = $(this).data('stickyDate');
  if (!e.date && stickyDate) {
    console.debug('restore stickyDate', stickyDate);
    $(this).datepicker('setDate', stickyDate);
    $(this).data('stickyDate', null);
  }
});

ASPX中的代码如下:

<div id="sandbox-container" class="row">
  <div class="col-lg-offset-4 col-md-offset-4 col-sm-offset-4 col-xs-offset-2">
    <div class="row">
      <input type="text" ng-model="datefrm" date-format="dd-MM-yyyy" class="textboxandbutton" placeholder="From" date-only />
    </div>
  </div>
  <div class="col-lg-offset-4 col-md-offset-4 col-sm-offset-4 col-xs-offset-2">
    <div class="row">
      <input type="text" ng-model="dateto" date-format="dd-MM-yyyy" class="textboxandbutton" placeholder="To" date-only>
    </div>
  </div>
</div>

当前格式为MM/dd/yyyy 日期显示方式如下:

2017/02/08

我需要将日期格式更改为:

dd-MM-yyyy

我要查看的数据是:

2017/08/02

感谢所有的帮助!

只需添加datepicker的format选项:

format: 'dd-mm-yyyy'

请在以下代码段中查找更多信息

 $('#sandbox-container input').datepicker({ autoclose: true, format: 'dd-mm-yyyy' }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.3.0/js/bootstrap-datepicker.js"></script> <link href="http://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.3.0/css/datepicker3.css" rel="stylesheet"/> <div id="sandbox-container"> <input type="text" type="text" class="form-control" /> </div> 

以下代码将起作用:

var date = "01/24/1977";
var datearray = date.split("/");
var newdate = datearray[0] + '-' + datearray[1] + '-' + datearray[2];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM