function getDate(args) {
if (!args) args = new Date();
var today = new Date(args);
var y = today.getFullYear();
var m = today.getMonth()+1;
var d = today.getDate();
if(m < 10) m = "0" + m;
if(d < 10) d = "0" + d;
var strDate = y + "-" + m + "-" + d;
return strDate;
}
function getTime(args) {
if (!args) args = new Date();
var today = new Date(args);
var h = ("0" + today.getHours()).slice(-2);
var i = ("0" + today.getMinutes()).slice(-2);
var s = ("0" + today.getSeconds()).slice(-2);
var strTime = h + ":" + i + ":" + s;
return strTime;
}
var serverTime = <%=new java.util.Date().getTime() %>;
function clock(millisecondsVal) {
var today = new Date();
serverTime = serverTime + millisecondsVal;
today.setTime(serverTime);
$("#nowDate").html(getDate(today));
$("#nowTime").html(getTime(today));
}
ready
setInterval("clock(1000)", 1000);
html
<font style="color:blue; font-weight:bold;">오늘</font>: <span id="nowDate" style="margin: 0px 6px 0px 0px;">0000-00-00</span>
<font style="color:blue; font-weight:bold;">현재시간</font>: <span id="nowTime" style="margin: 0px 6px 0px 0px;">00:00:00</span>
'jsp' 카테고리의 다른 글
script 년, 월, 일 차이 구하기 (0) | 2018.10.17 |
---|---|
dynatree 새로고침 (0) | 2018.03.05 |
숫자만 입력받는 script 이벤트 (0) | 2016.02.19 |
jquery dialog 호출 (0) | 2016.01.21 |
datepicker가 에디터 또는 activex에 가려질때 (0) | 2015.12.14 |