Javascript 如何显示第一个日期然后显示月份?
我正在使用Jquery显示日历。我已经创建了一个文本框,在文本框中单击后,日历将打开。但当我手动输入日期时,总是先输入第一个月,然后输入日期。但我想先定个日期再定个月。假设我以这种方式将2015年6月19日定为2015年6月19日,但它没有显示,因为我的代码将19作为一个月计算。请帮忙。 下面是我的代码Javascript 如何显示第一个日期然后显示月份?,javascript,Javascript,我正在使用Jquery显示日历。我已经创建了一个文本框,在文本框中单击后,日历将打开。但当我手动输入日期时,总是先输入第一个月,然后输入日期。但我想先定个日期再定个月。假设我以这种方式将2015年6月19日定为2015年6月19日,但它没有显示,因为我的代码将19作为一个月计算。请帮忙。 下面是我的代码 <script type="text/javascript"> $(function () { $("#datepicker").datepi
<script type="text/javascript">
$(function () {
$("#datepicker").datepicker();
});
</script>
<body>
<input type="text" id="datepicker">
</body>
非常简单,不需要库:
var date = new Date();
var firstDay = new Date(date.getFullYear(), date.getMonth(), 1);
var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);
或者您可能更喜欢:
var date = new Date(), y = date.getFullYear(), m = date.getMonth();
var firstDay = new Date(y, m, 1);
var lastDay = new Date(y, m + 1, 0);
使用
您需要定义属性:
$("#datepicker").datepicker({ dateFormat: 'dd-mm-yy' })
你可以根据需要改变
var newdate = new Date();
var curr_date = newdate.getDate();
var curr_month = newdate.getMonth();
var curr_year = newdate.getFullYear();
curr_year = curr_year.toString().substr(2,2);
document.write(curr_date+"-"+curr_month+"-"+curr_year);
@没问题。如果答案对你有帮助,不要忘记接受,欢迎你这么做。
var newdate = new Date();
var curr_date = newdate.getDate();
var curr_month = newdate.getMonth();
var curr_year = newdate.getFullYear();
curr_year = curr_year.toString().substr(2,2);
document.write(curr_date+"-"+curr_month+"-"+curr_year);