0

onTimer events. How?

asked 2009-09-28 14:04:02 +0800

lramellavotta gravatar image lramellavotta flag of Italy
200 1 8

I'd like to see the date and time on my web form. I tried to write this code but not working. Any idea?
Luca

<?page title="new page title" contentType="text/html;charset=UTF-8"?>
<zk>
<window id="ww" title="new page title" border="normal">
<label value="Test onTimer..."/>
<label id="lblOrologio" value="@{updTimer()}" style="background:#c5e6ef"/>
	<script type="text/javascript">
	void updTimer()
	{
		java.util.Calendar adesso = java.util.Calendar.getInstance();
		lblOrologio.setValue(adesso.toString());
		setTimeout("updTimer()",1000);
	}
	</script>					
</window>
<zscript>
<![CDATA[ 
         
          //value="@{java.util.Calendar.getInstance()}
]]>
</zscript>
</zk>

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2009-09-28 16:47:05 +0800

lramellavotta gravatar image lramellavotta flag of Italy
200 1 8

RESOLVED

	<label id="lblOrario" width="33%" />
	<timer id="timer" delay="1000" repeats="true" >
	<attribute name="onTimer">
		java.util.Calendar calendar = new GregorianCalendar();
		String orario;
		int ore = calendar.get(java.util.Calendar.HOUR);
		int min = calendar.get(java.util.Calendar.MINUTE);
		int sec = calendar.get(java.util.Calendar.SECOND);
		int gg = calendar.get(java.util.Calendar.DAY_OF_MONTH);
		int mm = calendar.get(java.util.Calendar.MONTH);
		int aa = calendar.get(java.util.Calendar.YEAR);		
									 
		if(calendar.get(java.util.Calendar.AM_PM) == 0) 
		orario = "A.M.";
		else 
		orario = "P.M.";
	lblOrario.setValue(gg+"/"+mm+"/"+aa+" "+ore+":"+min+":"+sec+" "+orario);	

link publish delete flag offensive edit

answered 2009-09-29 11:08:22 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

That's nice Luca. Thank you.

I have made a little modification for the european area.

regards
Stephan

				
   <label id="label2" width="33%" />
   <timer id="timer2" delay="1000" repeats="true">
      <attribute name="onTimer">

         java.util.Calendar calendar = new GregorianCalendar();
         String str_hour;
         String str_minute;
         String str_second;

         String str_day;
         String str_month;

         int hour = calendar.get(java.util.Calendar.HOUR);
         int min = calendar.get(java.util.Calendar.MINUTE);
         int sec = calendar.get(java.util.Calendar.SECOND);
         int day = calendar.get(java.util.Calendar.DAY_OF_MONTH);
         int month = calendar.get(java.util.Calendar.MONTH);
         int aa = calendar.get(java.util.Calendar.YEAR);

         if (calendar.get(java.util.Calendar.AM_PM) == 1)
             hour = 12 + hour;

         if (String.valueOf(hour).length() == 1)
             str_hour = "0" + hour;
         else
             str_hour = String.valueOf(hour);

         if (String.valueOf(min).length() == 1)
             str_minute = "0" + min;
         else
             str_minute = String.valueOf(min);

         if (String.valueOf(sec).length() == 1)
             str_second = "0" + sec;
         else
             str_second = String.valueOf(sec);

         if (String.valueOf(day).length() == 1)
             str_day = "0" + day;
         else
             str_day = String.valueOf(day);

         if (String.valueOf(month).length() == 1)
             str_month = "0" + month;
         else
             str_month = String.valueOf(month);

         label2.setValue(str_day + "." + str_month + "." + aa + " | " + str_hour + ":" + str_minute + ":" + str_second + " ");

      </attribute>
   </timer>

link publish delete flag offensive edit

answered 2009-09-29 11:12:32 +0800

lramellavotta gravatar image lramellavotta flag of Italy
200 1 8

You are the best.
thanks

/Luca

link publish delete flag offensive edit

answered 2009-10-02 09:15:54 +0800

xmedeko gravatar image xmedeko
1021 1 16
http://xmedeko.blogspot.c...

Why not to use flexible Java DateFormat?

Locale locale = org.zkoss.util.Locales.getCurrent();
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM,
			locale);
String strTime = dateFormat.format(Calendar.getInstance(locale).getTime());

link publish delete flag offensive edit

answered 2009-10-02 18:49:45 +0800

terrytornado gravatar image terrytornado flag of Germany
9393 3 7 16
http://www.oxitec.de/

updated 2009-10-02 19:23:09 +0800

Seems shorter :-) Many thanks xmedeko.

I have added the full qualifier that it can run in LUCAs zul template by the BSH.

	
<label id="lbl2" width="33%" />
<timer id="timer2" delay="1000" repeats="true">
<attribute name="onTimer">

	Locale locale = org.zkoss.util.Locales.getCurrent();
	java.text.DateFormat dateFormat = java.text.DateFormat.getDateTimeInstance(java.text.DateFormat.MEDIUM, java.text.DateFormat.MEDIUM,
			locale);
	String strTime = dateFormat.format(java.util.Calendar.getInstance(locale).getTime());
	colDate.setLabel(strTime);

</attribute>
</timer>

best
Stephan

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-09-28 14:04:02 +0800

Seen: 1,094 times

Last updated: Oct 02 '09

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