java - Displaying dynamic UTC clock time on JSP screen -


I want to use string variables in run () method and display values ​​on jsp screen. Please note that the value, which is a string variable in the run () method, changes every 1 second according to the code given below. Therefore my requirement is to display the value on the screen and change the speed dynamically.

  (OR)  

To make it simpler, I am trying to all the display UTC clock time, which is every one on the JSP screen Modifies in seconds.

  Applies the public square clock Runnable {JLabel jb; // Constructor Clock takes JLabel Public Clock (JLabel JB) {this.jb = jb; } Public Zero Run () {While (true) {try {// Thread Sleep & amp; Ever updates 1 second, so the clock changes every 1 second to jb.setText (timeNow ()); String dynaStr = timeNow (); Thread.Sleep (1000); } Grip (blocked predefined) {System.out.println (ex); }}} Public string timen () {calendar c = Calendar.getInstance (); Timezone z = C.Getimjon (); Int offset = z.frooffet (); If (z.inDaylightTime (new date ()) {offset = offset + z.getDSTSavings (); } Int offsetHrs = offset / 1000/60/60; Int offsetmin = offset / 1000/60% 60; System.out.println ("Offset:" + OffsetHairs); System.out.println ("Offset:" + Offsetin); C.add (calendar.HOUR_OF_DAY, (-offsetHrs)); C.add (Calendar Minute, (OffsetMans)); System.out.println ("GMT Time:" + c.getTime ()); Return c.getTime () ToString (); }}  

Javascript is not an example to use Java:

< Pre> var myVar = setInterval (function () {myTimer ()}, 1000); Function myTimer () {var date = new date (); Document.getElementById ("Demo"). InnerHTML = date.toIString (); }

The demo is being used for your display or whatever your display.

Here is a fully functional code, just paste and paste in the text document and replace the extension with HTML or HTML (JSP). Then double click to run in the browser.

  & lt; Html & gt; & Lt; Top & gt; & Lt; Title & gt; & Lt; / Title & gt; & Lt; Script type = "text / javascript" & gt; Var myVar = setInterval (function () {myTimer ()}, 1000); Var counter = 0; Function myTimer () {var date = new date (); Document.getElementById ("Demo"). InnerHTML = date.toIString (); } & Lt; / Script & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Span id = "demo" & gt; & Lt; / Span & gt; & Lt; / Body & gt; & Lt; / Html & gt;  

You can also use date.toUTCString () , which will give you the same thing only differently.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -