|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
JSP - Getting the Client System Date and Time to Display on Page
Hi, I need an immediate help over this. Thanks in advance.
Problem: I have my application running on server that is there in some other time zone. I need to display the date and time zone of the user system on the home page of the application. Curently it is displaying the date and time of the zone where the server is located. I have used alomost each and every JavaAPI related to this in my JSP but again and again it is showing me the server's date and time. Pls Help!!!! RVA |
|
#2
|
||||
|
||||
|
Perhaps I give you a solution that you've tried already
and that did not work out. Anyway, you should take a look at the locale. The Locale is a class that determines specific properties of the computer of the user. In "Java, how to program sixth edition" of Deitel, I found this piece of code. Code:
<% // get client locale java.util.Locale locale = request.getLocale(); // get Dateformat for client's locale java.text.DateFormat dateFormat = java.text.DateFormat.getDateTimeInstance( java.text.DateFormat.LONG, java.text.DateFormat.LONG, locale); %> <%=dateFormat.format( new java.util.Date() ) %> Try this out and let us know if this was the solution. |
|
#3
|
|||
|
|||
|
Well, we'd faced a similar situation. My team mate added a attribute, say localTime in our form and wrote a piece of Javascript code to find the time.We called this code on load of our page and which set teh local date time value to our form attribute.It was then used in our JSP to display the Local time
Find the piece of code below : JS function showDate(){ var datetime= new Date(); var dateonly=datetime.getDate(); var dateyear=datetime.getFullYear(); var datemonth=datetime.getMonth(); var hours=(datetime.getHours()); var minutes=(datetime.getMinutes()); var seconds=(datetime.getSeconds()); var daytime="AM"; if (hours>12) { daytime="PM"; hours=hours-12; } if(hours==12) daytime="PM" var totaltime=dateonly+"/"+datemonth+"/"+dateyear+" "+hours+":"+minutes+":"+seconds+" "+daytime; document.forms[1].timedate.value=totaltime; } Now the timedate is added to oour form and on page load we are calling this method javascript:showDate(); We are displaying this on the JSP as below <td width="100%" align="RIGHT"><html:text property="timedate" name="OurFormName" style="background-color:transparent;border:0px solid white;"/></td> Hope it helps AppleMan |
![]() |
| Viewing: Dev Articles Community Forums > Programming > Java Development > JSP - Getting the Client System Date and Time to Display on Page |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|