フロントページでタイムスタンプを年月日に変更した場合は分秒表示
11973 ワード
ここでは、時刻プラグインMy 97 DatePickerの例を示します.
<1>パッケージ
<2>フロントページ:
<3>jQueryを利用してidで値をとる:
<1>パッケージ
<script type="text/javascript" src="lib/My97DatePicker/WdatePicker.js"></script>
<2>フロントページ:
<div class="row cl">
<label class="form-label col-2"> :</label>
<div class="formControls col-9">
<input type="text" onfocus="WdatePicker({minDate:'#F{$dp.$D(\'endDate\')||\'%y-%M-%d\'}'})" id="startDate" name="startDate" class="input-text Wdate" style="width:120px;">-
<input type="text" onfocus="WdatePicker({minDate:'#F{$dp.$D(\'startDate\')||\'%y-%M-%d\'}'})" id="endDate" name="endDate" class="input-text Wdate" style="width:120px;">
</div>
</div>
<3>jQueryを利用してidで値をとる:
$('#startDate').val(dates("Y-m-d",bizData.starttime));
$('#endDate').val(dates("Y-m-d",bizData.endtime));
<4>次のコードを共通のcommonに書き込む.jsでは、呼び出しでOK:(ここではdatesメソッドのみ)// ·
var timeFormat = function(ms, showDay) {
if (typeof ms == 'string') {
ms = parseInt(ms);
}
var timeLocal = new Date(ms);
var year = timeLocal.getYear() + 1900;
var month = timeLength(timeLocal.getMonth() + 1);
var day = timeLength(timeLocal.getDate());
var hour = timeLength(timeLocal.getHours());
var minutes = timeLength(timeLocal.getMinutes());
var second = timeLength(timeLocal.getSeconds());
var weekDay = timeDay[timeLocal.getDay()];
if (showDay == null) {
var timeNew = year + "-" + month + "-" + day;
} else if (!showDay) {
var timeNew = year + "-" + month + "-" + day + " " + hour + ":"
+ minutes + ":" + second;
} else {
var timeNew = year + "-" + month + "-" + day + " " + hour + ":"
+ minutes + ":" + second + " " + weekDay;
}
return timeNew;
};
// ·
var dates = function(format,ms) {
if ( typeof ms == 'string') {
ms = parseInt(ms);
}
var timeLocal = new Date(ms);
var year = timeLocal.getFullYear();
var month = timeLength(timeLocal.getMonth() + 1);
var day = timeLength(timeLocal.getDate());
var hour = timeLength(timeLocal.getHours());
var minutes = timeLength(timeLocal.getMinutes());
var second = timeLength(timeLocal.getSeconds());
return format.replace("Y",year).replace("m",month).replace("d",day).replace("H",hour).replace("i",minutes).replace("s",second);
};