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

  • Home
  • SEARCH
  • 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

Ask A Question

Stats

  • Questions 150k
  • Answers 150k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'm 90% certain that var test = dc.TableBlah.FirstOrDefault(_blah => _blah.id… May 12, 2026 at 9:46 am
  • Editorial Team
    Editorial Team added an answer The url you are looking for is in the js… May 12, 2026 at 9:46 am
  • Editorial Team
    Editorial Team added an answer Maintainability aside - what you are doing will perform well,… May 12, 2026 at 9:46 am

Related Questions

I am calling my makewindows function from a PHP file like so: echo <a
I have made a WinForms application with a custom richtextbox control. I am referring
I have a complicated background image with a lot of small regions that need
Does anyone have a good way of finding if a string contains malformed XHTML

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.