Clock displays server or client datetime live. AutoSync feature in server mode can sync the clock with server periodically.
<style>
.ui-analog-clock {
width: 200px;
}
</style>
<div class="card">
<h:form>
<h5 class="mt-0">Client</h5>
<p:clock />
<h5>Server</h5>
<p:clock pattern="HH:mm:ss dd.MM.yyyy" mode="server"/>
<h5>Custom</h5>
<p:clock mode="server" value="#{clockView.dateTime}"/>
<h5>Analog</h5>
<p:clock displayMode="analog"/>
</h:form>
</div>
package org.primefaces.showcase.view.misc;
import jakarta.annotation.PostConstruct;
import jakarta.faces.view.ViewScoped;
import jakarta.inject.Named;
import java.io.Serializable;
import java.time.LocalDateTime;
import io.quarkus.runtime.annotations.RegisterForReflection;
@Named
@ViewScoped
@RegisterForReflection(serialization = true)
public class ClockView implements Serializable {
private LocalDateTime dateTime;
@PostConstruct
public void init() {
dateTime = LocalDateTime.now().plusYears(37).plusMonths(3).plusHours(4);
}
public LocalDateTime getDateTime() {
return dateTime;
}
public void setDateTime(LocalDateTime dateTime) {
this.dateTime = dateTime;
}
}