我需要使用get方法发送变量,但日期格式应为“dd-monthName-YYYY”,例如“02-February-2015”。
可以使用HTML5 type =“date”吗?
如果不能,那我该怎么做?
答案 0 :(得分:-1)
你可以这样做:
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>
<input id="datefield" type="date" />
<script>
var monthNames = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ];
$("#datefield").change(function () {
var val = $(this).val();
console.log(val);
var d = new Date(val);
console.log(d.getDate() + '-' + monthNames[d.getMonth()] + '-' + d.getFullYear());
});
</script>
</html>
结果:
2015-02-02
2-February-2015