js 快速集成开发:easyui 时间控件格式化
例如:
申明变量:
<td align="center" width="80px" height="35px">申请日期起:</td>
<td width="170px">
<input type="text" id="xzqsrq" class="easyui-datebox bwui_text " data-options="formatter:common.util.formatDate" comboname="qsrq" style="display: none;">
</td>
<td align="center" width="80px" height="35px">申请日期止:</td>
<td width="170px">
<input type="text" id="xzzzrq" class="easyui-datebox bwui_text" data-options="formatter:common.util.formatDate" comboname="zzrq" style="display: none;">
</td>
获取时间:
var currentMonthFirstDate = getMonthFirstDate();
var currentDate = getCurrentDate();
取值:
var xzqsrq = $('#xzqsrq').datebox('setValue', currentMonthFirstDate);//起始时间
var xzzzrq = $('#xzzzrq').datebox('setValue', currentDate);//当前时间
/**
* 获取当前日期
*
* @returns {String}
*/
function getCurrentDate() {
var currentDate = new Date();
var year = currentDate.getFullYear();
var month = currentDate.getMonth() + 1;
var date = currentDate.getDate();
if (parseInt(month) < 10) {
month = "0" + month;
}
if (parseInt(date) < 10) {
date = "0" + date;
}
return year + "-" + month + "-" + date;
}
/**
* 获取当月一号
*
* @returns {String}
*/
function getMonthFirstDate() {
var currentDate = new Date();
var year = currentDate.getFullYear();
var month = currentDate.getMonth() + 1;
var date = "01";
if (parseInt(month) < 10) {
month = "0" + month;
}
return year + "-" + month + "-" + date;
}