<f:view>
<af:document title="untitled1.jspx" id="d1">
<af:clientListener method="GetClock" type="load"/>
<f:facet name="metaContainer">
<af:resource type="javascript" source="resources/js/timer.js"/>
</f:facet>
<af:messages id="m1"/>
<af:form id="f1">
JavaScript file: timer.js
function GetClock() {
var today = new Date();
tday = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
tmonth = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
smonth = new Array("JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC");
var d = new Date();
var nday = d.getDay(), nmonth = d.getMonth(), ndate = d.getDate(), nyear = d.getFullYear();
var nhour = d.getHours(), nmin = d.getMinutes(), nsec = d.getSeconds(), ap;
if (nhour == 0) {
ap = " AM";
nhour = 12;
}
else if (nhour < 12) {
ap = " AM";
}
else if (nhour == 12) {
ap = " PM";
}
else if (nhour > 12) {
ap = " PM";
nhour -= 12;
}
if (nmin <= 9)
nmin = "0" + nmin;
if (nsec <= 9)
nsec = "0" + nsec;
var dateandTimeStr = "" + tday[nday] + ", " + tmonth[nmonth] + " " + ndate + ", " + nyear + " " + nhour + ":" + nmin + ":" + nsec + ap + "";
var dateandTimeStr1 = "" + (nmonth + 1) + "/" + ndate + "/" + nyear + " " + nhour + ":" + nmin + ap + "";
document.getElementById('DateStr').innerHTML = "Hello " + dateandTimeStr;
t = setTimeout('GetClock()', 500);
}
<af:outputText id="DateStr" value="DateStr1" clientComponent="true"/>
No comments:
Post a Comment