getting date with millisiconds in Javascript and passig it to an asp script

I have a script in asp which requires the date and tiem with milliseconds

asp gives up to seconds.

javascript gives miliseconds.

The idea is to grab the whole date fom javascript ans pass it to asp.

Or is there any other way?

Thx
robrodpAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
You would have to pass it as text.  What are you trying to do or  use it for?
0
robrodpAuthor Commented:
As text its ok... it is a requirement of a client. Just to use it as a regular text asp variable
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Yes that is what you will need to do.  Or  you can store it in mssql server with milliseconds and that way if you need to do any calculations, you can use mssql server.   But if you just need to view it, then you have to use it as text or manually do the math.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

robrodpAuthor Commented:
That is all I need. The tdate in text with milliseconds. I have no idea of how to get it in JSand use it inASP
0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
Server side VBScript doesn't allow you to easily get the milliseconds in a time variable:

http://classicasp.aspfaq.com/date-time-routines-manipulation/can-i-get-millisecond-accuracy-in-asp.html

You would need to get it in Javascript (client side), save it to a hidden field, then submit the form to retrieve it server side.

To get it in Javascript you would do something like

var d = new Date();
var n = d.getMilliseconds();

Open in new window

0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
Then store it in a hidden field and submit it to work with that value server side
0
robrodpAuthor Commented:
Any ideas?
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
It depends on how you want to use it.  Since you have it in js already you can use javascript to update a field.  Then when you post/submit the form it will be as if the data was typed in.  

Or you can  use ajax to update another page that does the processing as well.  

What are you trying to do?  Can you outline the steps and what you are trying to update at the end.
0
robrodpAuthor Commented:
How do I store it in a hidden field?
0
robrodpAuthor Commented:
In asp i do this

variable=now()

I get  the datw with seconds and

<r%esponse.write variable%>

I need the variable to have milliseconds. That is my clients requirement

No forms to submit... nothing
0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
OK then you can just do it all in JavaScript:

<HTML>
<head>
<script type="text/JavaScript">
function showtime() {
var d = new Date();
var n = d.getMilliseconds();
document.getElementById("theTime").innerHTML = n;
}
</script>
</head>
<body onload="showtime()">
<div id="the time"></div>
</body>
</HTML>

Open in new window

0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
It depends on how you are getting the value and where it is to be put.
This updates the value of an input when the page loads.  In your case, it is when you get the value from js.  Without seeing your code, we can only guess.

http://jsbin.com/nedogo/1/edit
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
<script type="text/javascript">
function myFunction() {
    document.getElementById("abc").value = "some value";

}
</script>
</head>
<body onload="myFunction()">
  <input id="abc">

</body>
</html>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
robrodpAuthor Commented:
Hi

Maybe what I want is not possible

I need

<%response.write thetime%>

Maybe js is not the way to go
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Again, if you can outline what you are doing, we can help.
0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
Since you cannot easily get milliseconds on the sever side, you need to pass that variable to a JavaScript function which can then get the milliseconds. So simply modify my function to

<HTML>
<head>
<script type="text/JavaScript">
function showtime() {
var d = new Date("<℅=thetime%>");
var n = d.getMilliseconds();
document.getElementById("theTime").innerHTML = n;
}
</script>
</head>
<body onload="showtime()">
<div id="the time"></div>
</body>
</HTML>
  

Open in new window


Assuming thetime is a valid date variable this should work
0
Ray PaseurCommented:
Beware that the time on the client machine may not be the same time as the time on the server.
0
robrodpAuthor Commented:
Mh... just what I needed

Thx
0
robrodpAuthor Commented:
At the end of the day I just wenty ahead and printed the millliseconds and that was enough.
0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
At the end of the day I just wenty ahead and printed the millliseconds and that was enough.

could you post the code you used? you shouldn't accept answers "just because", as they will be of no use to anyone in the future that uses this question in a search...
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
Ray and BM,  please re read the question here.  "I have a script in asp which requires the date and tiem with milliseconds".  

There is no mention of exactly how all this is being  used.   It is a simple matter of grabbing something from javascript and displaying to the screen.  

The thread has helped solve the issue.  No need to keep badgering.
0
robrodpAuthor Commented:
As I said I wanted to show the milliseconds, here is the code

<HTML>
<head>
<script type="text/JavaScript">
function showtime() {
var d = new Date();
var n = d.getMilliseconds();
document.getElementById("theTime").innerHTML = n;
}
</script>
</head>
<body onload="showtime()">
<div id="thetime"></div>
</body>
</HTML>

Open in new window

0
Ray PaseurCommented:
I guess I do not know any use for the milliseconds.  Every second, the number of elapsed milliseconds changes 1,000 times.  Whatever event triggers the acquisition of the current count of milliseconds happens too fast for my Rolex (and life experiences).  Best of luck with your project, ~Ray
0
robrodpAuthor Commented:
thx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.