TimeAgo generates automatically updating fuzzy timestamps (e.g. "4 minutes ago"). Based on jquery-timeago by Ryan McGeary.
Fuzzy timestamps for dates in the past and in the future. The titlePattern sets the tooltip with the exact date.
You've opened this page .
PrimeFaces Extensions was first released .
The next month is .
<div class="card">
<h5>Basic Usage</h5>
<p>Fuzzy timestamps for dates in the past and in the future. The <code>titlePattern</code> sets the tooltip with the exact date.</p>
<p>
You've opened this page
<pe:timeAgo value="#{basicTimeAgoController.created}"
titlePattern="MMMM dd yyyy hh:mm a" style="font-weight:bold" />.
</p>
<p>
PrimeFaces Extensions was first released
<pe:timeAgo value="#{basicTimeAgoController.firstRelease}"
titlePattern="MMMM dd yyyy" style="font-weight:bold"/>.
</p>
<p>
The next month is
<pe:timeAgo value="#{basicTimeAgoController.nextMonth}"
titlePattern="MMMM dd yyyy" style="font-weight:bold"/>.
</p>
</div>
package org.primefaces.extensions.showcase.controller.timeago;
import java.io.Serial;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;
import jakarta.faces.view.ViewScoped;
import jakarta.inject.Named;
/**
* @author Jasper de Vries <[email protected]>
*/
@Named
@ViewScoped
public class BasicTimeAgoController implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private final OffsetDateTime created = OffsetDateTime.now();
private final LocalDateTime firstRelease = LocalDate.of(2012, Month.JANUARY, 23).atStartOfDay();
private final LocalDateTime nextMonth = LocalDateTime.now()
.plusMonths(1)
.withDayOfMonth(1)
.truncatedTo(ChronoUnit.DAYS);
public OffsetDateTime getCreated() {
return created;
}
public LocalDateTime getFirstRelease() {
return firstRelease;
}
public LocalDateTime getNextMonth() {
return nextMonth;
}
}