[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2014-08-28
24
Medium Priority
?
266 Views
Last Modified: 2014-08-29
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
0
Comment
Question by:robrodp
  • 10
  • 6
  • 5
  • +1
23 Comments
 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 40290986
You would have to pass it as text.  What are you trying to do or  use it for?
0
 

Author Comment

by:robrodp
ID: 40290990
As text its ok... it is a requirement of a client. Just to use it as a regular text asp variable
0
 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 40291027
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:robrodp
ID: 40291032
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
 
LVL 34

Expert Comment

by:Big Monty
ID: 40291370
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
 
LVL 34

Expert Comment

by:Big Monty
ID: 40291372
Then store it in a hidden field and submit it to work with that value server side
0
 

Author Comment

by:robrodp
ID: 40291378
Any ideas?
0
 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 40291388
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
 

Author Comment

by:robrodp
ID: 40291393
How do I store it in a hidden field?
0
 

Author Comment

by:robrodp
ID: 40291402
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
 
LVL 34

Expert Comment

by:Big Monty
ID: 40291449
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
 
LVL 54

Accepted Solution

by:
Scott Fell,  EE MVE earned 1000 total points
ID: 40291457
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
 

Author Comment

by:robrodp
ID: 40291475
Hi

Maybe what I want is not possible

I need

<%response.write thetime%>

Maybe js is not the way to go
0
 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 40291484
Again, if you can outline what you are doing, we can help.
0
 
LVL 34

Assisted Solution

by:Big Monty
Big Monty earned 1000 total points
ID: 40291501
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
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40291677
Beware that the time on the client machine may not be the same time as the time on the server.
0
 

Author Closing Comment

by:robrodp
ID: 40291679
Mh... just what I needed

Thx
0
 

Author Comment

by:robrodp
ID: 40291701
At the end of the day I just wenty ahead and printed the millliseconds and that was enough.
0
 
LVL 34

Expert Comment

by:Big Monty
ID: 40291709
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
 
LVL 54

Expert Comment

by:Scott Fell, EE MVE
ID: 40291714
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
 

Author Comment

by:robrodp
ID: 40291717
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
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40291753
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
 

Author Comment

by:robrodp
ID: 40291775
thx
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question