Merhaba,
f:convertDateTime string ifadeyi belirtilen tarih formatına dönüştüren standart JSF etiketidir.
Managed Bean
import java.util.Date;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
/**
*
* @author Omer Faruk KURT
* @blog https://ofarukkurt.blogspot.com/
* @Created on date 23/02/2017 10:09:47
*/
@ManagedBean
public class Bean implements java.io.Serializable {
private static final long serialVersionUID = 536742571209526117L;
private Date date;
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
@PostConstruct
public void init() {
date = new Date();
}
}
index.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<h:form>
<h:outputText value="#{bean.date}"/>
<br/>
<h:outputText value="#{bean.date}">
<f:convertDateTime dateStyle="default" type="both"/>
</h:outputText>
</h:form>
</h:body>
</html>
Çıktı
Thu Feb 23 13:42:55 GMT+03:00 2017 23.Şub.2017 10:42:55
dateStyle="full" type="both"
<h:outputText value="#{bean.date}">
<f:convertDateTime dateStyle="full" type="both"/>
</h:outputText>
Çıktı
23 Şubat 2017 Perşembe 10:43:29
pattern
<h:outputText value="#{bean.date}">
<f:convertDateTime pattern="dd.MM.yyy"/>
</h:outputText>
Çıktı
23.02.2017
<h:outputText value="#{bean.date}">
<f:convertDateTime pattern="dd.MM.yyy hh:mm:ss"/>
</h:outputText>
23.02.2017 01:48:59
Burada patternda kullanmış olduğum formatta "hh" olarak yazdığımızdan dolayı am/pm şeklinde yazıyor. Bunu 24 saat sistemi ile yazdırmak istediğimizde "HH" olarak yazmamız gerekmektedir.
<h:outputText value="#{bean.date}">
<f:convertDateTime pattern="dd.MM.yyy HH:mm:ss"/>
</h:outputText>
23.02.2017 13:52:19
locale
<h:outputText value="#{bean.date}">
<f:convertDateTime locale="tr"/>
</h:outputText>
<br/>
<h:outputText value="#{bean.date}">
<f:convertDateTime locale="en"/>
</h:outputText>
Çıktı
23.Şub.2017
Feb 23, 2017
0 Yorumlar