Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JSP and User's Current Date/Time

Status
Not open for further replies.

jem122974

Programmer
Nov 1, 2001
114
US
I would like to pull the user's current date, time and timezone to store in the DB. Right now I do a new Date() but that gets the current date from the server. Any thoughts?
 
Hi,

You have to use JavaScript on the client side to create the date into a html hidden field and send that to the server to store the Data on client's m/c.

Cheers,
Venu
 
Use the date object in javascript to accomplish this. This will create the date and store it in the client side javascript variable str, as well as in the hidden html variable currentDate.
Code:
<input type=hidden name=currentDate value=''>
<script language=javascript>
  var now = new Date();
  var str = '';
  str += now.getMonth() + '/';
  str += now.getDate() + '/';
  str += now.getFullYear();
  formName.currentDate.value = str;
</script>
Note: I use the date methods to form the string because javascript defaults to the January 1, 2004 format.

-kaht

banghead.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top