Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 208055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:47:26+00:00 2026-05-11T17:47:26+00:00

I made a function which displays date on the webpage,, and i uploaded the

  • 0

I made a function which displays date on the webpage,, and i uploaded the same onto some server…

But when i changed the date of my system, i noticed that the date is dependent on client machine..

Is it not possible to get the date from actual time server and embed that code into my program..

Hope i am able to explain my doubt.. Please give some solution to this with small sample code..that would be helpful..

Thanks a lot..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:47:27+00:00Added an answer on May 11, 2026 at 5:47 pm

    If you have written it in javascript, well…that always executes on the client side. If you are calculating date through javascript, its too late, that code is gone.

    To solve this, you would have to make your js function receive data through parameters, and that data should be calculated on the server side.

    You could do something like.

    <%@ page import ="java.util.Date" %><%--Imports date --%>
    <% Date date = new Date();
       String strdate = date.toString();//could be formatted using SimpleDateFormat.
    %>
    
      <!--must be inside a form -->  
      <input type="text" value="javascript:showDate('<%=strdate%>');"/>
    
      <!--must be inside a table-->
      <td>javascript:showDate(<%=strdate%>);</td>
    

    Or more elegantly, get server date in your java class, and write it to request:

    //formattedDate is defined above, in the format you like the most. Could be a 
    //java.util.date or a String
    request.setDate("date",formattedDate);
    

    And then, in your jsp, using for example, JSTL

    <c:out value="${formattedDate}"/>
    

    Or,

    <% //this java code is run on the server side.
        String strdate = (String)request.getAttribute("date"); 
     %>
    <%=strdate%><!-- prints strdate to jsp. Could put it in a table, form, etc -->
    

    EDIT: In response to your comment, you should:

    <%--Imports java packages --%>
    <%@ page import ="java.util.Date" %>
    <%@ page import ="java.text.SimpleDateFormat"%>
    
    <%-- Java code --%>
    <% Date date = new Date();
       Calendar calendar = Calendar.getInstance(TIME_ZONE).setTime(date);
       SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yy");
       String strdate = sdf.format(calendar.getTime());
    %>
    
    <html>
     <body>
     <!-- Does not need to use javascript. All work is done on the server side.-->
     <table>
       <tr>
         <td><%=strdate%></td>
       </tr>
     </table>
     </body>
    </html>
    

    I have no idea what your time zone is, but I’m sure you do.
    Calendar.getInstance() takes an instance of TimeZone as a parameter. That should do it

    Take a look:

    http://java.sun.com/javase/6/docs/api/java/util/TimeZone.html

    http://java.sun.com/javase/6/docs/api/java/util/Calendar.html

    Interesting link about JSP

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi have made this function which is made to replicate an error that I
I've made some function that generates an email template. Code it generates is pure
I made a button widget in jQuery which displays an icon. Now when I
For some months I've been working on a home-made operating system. Currently, it boots
I have made a script which slides thought some customers quotes. See code below
I am using a telerik grid control, which displays a grid with some other
I made some CMS in PHP which manipulates with data from MySQL. In my
I made a certain piece of functionality which works perfectly on Chrome, but not
I have some code which displays three images and a respective div under each
Anyone got a ready made function that will take an XML string and return

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.