0

Convert Long to Date in Listbox

asked 2009-12-17 09:11:01 +0800

ziftech gravatar image ziftech
87 2

Hi!

I want to show in listitems values from database, contained date and time in BigInt format which I mapped to Long.

value example:1261057621000
desired format: 17.12.2009 18:07

I tried this approach:

<zscript>
	import java.text.SimpleDateFormat;
	import java.util.Date;
		 
	 public String transform(Long lng)
	 {
	 	SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm");
	 	Date dtime = new Date(lng);
	 	System.out.println(dtime.toString());
	 	return format.format(dtime);
	 }
	 
</zscript>

...
<listcell label="@{transform(zx1.timeopen)}" />
...
but no result

Is there any appropriative solution?

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2009-12-17 09:58:49 +0800

ziftech gravatar image ziftech
87 2

ok, I solve it :)

public class LongDateConverter implements TypeConverter{

	public Object coerceToBean(Object val, Component comp) {
		// TODO Auto-generated method stub
		return null;
	}

	public Object coerceToUi(Object val, Component comp) {
		DateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm");
		Long time = (Long) val;
		Date dtime = new Date(time*1000); //1000 nedded for Moodle values
				
		return format.format(dtime);
	}

}

usage: <listcell label="@{zx1.timeopen, converter='mypack.converter.LongDateConverter'}" />

link publish delete flag offensive edit

answered 2009-12-17 17:02:30 +0800

haddorp gravatar image haddorp
81 2 3

Looking on the last code I remember a question I have had before. How can you achieve making the SimpleDateFormat configuratable? For example depending on the user's request locale?

link publish delete flag offensive edit

answered 2009-12-17 18:11:39 +0800

robertpic71 gravatar image robertpic71
1275 1

updated 2009-12-17 18:11:51 +0800

See my page for some dateexamples.

/Robert

link publish delete flag offensive edit
Your reply
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

Follow

RSS

Stats

Asked: 2009-12-17 09:11:01 +0800

Seen: 669 times

Last updated: Dec 17 '09

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