Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

timestamp using javascript

 
swapnil paranjape
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi how can i get the timestamp of the web page using javascript?i want to know the exact time at which the operation was performed?how should i use javascript for this?

thanx in advance.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You do not want to use JavaScript to do this since it is using the users time, Are all the clocks in your house correct? My microwave is blinking 12:00. my point is the time may be incorrect, plus you have to deal with timezone issues.

The easiest solution if you are using a Database is to set the column to a default value of the date. Then you do not have to worry. Or just grab the time with a server side language.

Eric
 
swapnil paranjape
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You do not want to use JavaScript to do this since it is using the users time, Are all the clocks in your house correct? My microwave is blinking 12:00. my point is the time may be incorrect, plus you have to deal with timezone issues.

The easiest solution if you are using a Database is to set the column to a default value of the date. Then you do not have to worry. Or just grab the time with a server side language.

Thanx Eric
you are absolutly right .
But suppose ignore timezone issues and i just want to have the timestamp for suppose alertbox.i dont want to use serverside language.
using html and javascript i want to find out the timestamp for the any of the functionality eg. alertbox(what time alertbox appeared and what time i clicked ok on it!).
how should i do that?
can u provide some code or example?
thanx again.

swapnil
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure you can incorporate the JavaScript time into an alert. I interpreted the question as you were going to save this value on the server.

To get the time in JavaScript you can use

var strTime = new Date().toLocaleString();

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic