How to format the date value in a listcell of a listbox

asked 2011-08-30 11:27:21 +0800

GGW gravatar image GGW

updated 2014-04-30 06:47:29 +0800

chillworld gravatar image chillworld flag of Belgium
5322 4 9

In the following code, the date in the "Last Accessed" column is in the format of "Jul 5, 2001 12:00:00". I want to just list the date part without the time part. How to do that? Thanks in advance. --GGW

                    <listheader label="Client" width="90px" sort="auto(client.code)" />
                    <listheader label="Country" width="70px" sort="auto(country.shortName)" />
                    <listheader label="Last Accessed" width="110px" sort="auto(date)" />
                    <listheader label="Subject Matter" sort="auto(subjectMatter)" /> 

                <listitem self="@{each=acase}" value="@{acase}">
                    <listcell label="@{acase.client}" />
                    <listcell label="@{acase.country}" />
                    <listcell label="@{acase.date}" />
                    <listcell label="@{acase.subjectMatter}" />

delete flag offensive retag edit

4 Answers

Sort by ยป oldest newest most voted

answered 2012-06-14 20:17:17 +0800

nosrednakram gravatar image nosrednakram
26 1

updated 2014-04-30 06:53:13 +0800

chillworld gravatar image chillworld flag of Belgium
5322 4 9

Playing with MVVM and this works:

<listcell label="@load(message.posted)
                 @converter('formatedDate',format='yyyy/MM/dd h:ma')" />
link publish delete flag offensive edit

answered 2011-08-31 12:23:12 +0800

TonyQ gravatar image TonyQ

haha , yes. I miss the one. :)

link publish delete flag offensive edit

answered 2011-08-31 04:10:32 +0800

GGW gravatar image GGW

Thanks, TonyQ.

Along your hint, I found that ZK actually provides a stock DateFormatConverter:

public class DateFormatConverter
extends java.lang.Object
implements TypeConverter

Convert a Date or a Timestamp to a formated date String. You can specify the date format in 'format' annotation, and the converter will format the given date for you. e.g.

<label value="@{mydate, converter='org.zkoss.zkplus.databind.DateFormatConverter'}" self="@{format(yyyy/MM/dd)}"/>

If format is not given, default to 'MM/dd/yyyy'.

link publish delete flag offensive edit

answered 2011-08-30 11:57:22 +0800

TonyQ gravatar image TonyQ

When you are using databinding , you could try to use converter .

Here's the document,

And here's a online testable sample for it, hope it helps.

package j1t0gtrk$v1;

import java.util.*;

public class Person{

private String firstName;
private String lastName;
private Date birthday;

public Person(){

public Person(String first,String last,Date bir){
this.firstName = first;
this.lastName = last;
this.birthday = bir;


public void setFirstName(String firstName){
this.firstName = firstName;

public String getFirstName(){
return this.firstName;

public void setLastName(String lastName){
this.lastName = lastName;

public String getLastName(){
return this.lastName;

public void setBirthday(Date bir){
this.birthday = bir;

public Date getBirthday(){
return this.birthday;


package j1t0gtrk$v1;

import org.zkoss.zkplus.databind.TypeConverter;
import org.zkoss.zul.Listcell;
import java.text.SimpleDateFormat;
import java.util.Date;

public class MyDateTypeConverter implements TypeConverter {

private static SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");

public Object coerceToBean(java.lang.Object val,
org.zkoss.zk.ui.Component comp) {
return null;

public Object coerceToUi(java.lang.Object val,
org.zkoss.zk.ui.Component comp) {
return sdf.format((Date) val);

<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit"?>

<window width="500px">
import j1t0gtrk$v1.Person;
//prepare the example persons List
List persons = new ArrayList();
persons.add(new Person("Tony", "Wang", new Date(86,11,23)));
persons.add(new Person("Tracy", "Kao", new Date(85,10,20)));
persons.add(new Person("Jone", "Lee", new Date(80,10,20)));

<listbox rows="4" model="@{persons}">
<listheader label="First Name" width="100px" />
<listheader label="Last Name" width="100px" />
<listheader label="Married" width="100px" />
<listitem self="@{each=person}">
<listcell label="@{person.firstName}" />
<listcell label="@{person.lastName}" />
label="@{person.birthday, converter='j1t0gtrk$v1.MyDateTypeConverter'}" />

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools




Asked: 2011-08-30 11:27:21 +0800

Seen: 957 times

Last updated: Apr 30 '14

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More