Ariel
Ariel

Reputation: 57

(XPages)How to show the dynamic time?

I want to show the dynamic time in XPages.

Now I already tried this code in the computed field, the code like this:

var NowDate = new Date();
var YY = NowDate.getFullYear();
var MM = NowDate.getMonth()+1;
var DD = NowDate.getDate();
var HH = NowDate.getHours();
var H = "";
var Mins = NowDate.getMinutes();
var SS = NowDate.getSeconds();
var S = "";

if(MM < 10){
    MM = "0" + MM;
}
if(DD <10){
    DD = "0" + DD;
}
if(HH >= 12){
    H = HH + "PM";
}else if(HH == 10 || HH == 11){
    H = HH + "AM";
}
else{
    H = "0" + HH + "AM";
}
if(Mins < 10){
    Mins = "0" + Mins;
}
if(SS < 10){
    S = "0" + SS;
}else{
    S = SS;
}
return YY + "/" + MM + "/" + DD + " " + H + ":" + Mins + ":" + S ;

But the result is the static display, not dynamic display.

Did anyone already use dynamic time in XPages?

Upvotes: 0

Views: 97

Answers (1)

Per Henrik Lausten
Per Henrik Lausten

Reputation: 21709

You should not use server side code for this. Instead just use client side Javascript. Here's an example: https://stackoverflow.com/a/18229123/785061.

Upvotes: 4

Related Questions