Solved

Get Client Time

Posted on 2013-12-24
4
374 Views
Last Modified: 2013-12-25
Hello Experts,

I'm working with VB.Net and I want to get the client DateTimeStamp and populated to the "DTS" textbox everytime and AddPage is opened.
How can I do it using jQuery or JS?  

Many thanks!
0
Comment
Question by:JimiJ13
  • 2
  • 2
4 Comments
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 39738988
Try below and I have a working sample here http://jsbin.com/UQAHegI/1/edit?html,js,output
var date1 = new Date(); 
var date2=date1.toString();
$('div#result').text(date2);
$('input#time').val(date2);

Open in new window

  <div id="result"></div>
  <input id="time" name="time">

Open in new window

0
 

Author Comment

by:JimiJ13
ID: 39739097
Hi Padas,

Thanks for your quick reply.  
Seems to work with HTML page.  
How can I format the the output as "12/25/2013 9:53 PM" and how to populate with an ASPX TextBox?

Regards,
0
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 total points
ID: 39739182
I have updated the date http://jsbin.com/UQAHegI/2/edit?html,js,output
var ampm = 'AM';
var date = new Date(),
    month = date.getMonth() + 1, // 0-11,
    day = date.getDate(),
    year = date.getFullYear(),
    hour = date.getHours(),
    minute = date.getMinutes();
//year   = year.toString().slice(2,4);
year = year.toString();
month = month < 10 ? "0" + month : month;
minute = minute < 10 ? "0" + minute : minute;
if (hour >= 12) {
    ampm = 'PM';
    if (hour > 12) {
        hour = hour - 12;
    }
}
theTime = hour + ':' + minute + ' ' + ampm;
theFullDate = day + '/' + month + '/' + year + ' ' + theTime;
$('div#result').text(theFullDate);
$('input#time').val(theFullDate);

Open in new window

As far as getting the date to your form input, jquery/javascript is run after the page loads and your serverside code runs on the server before the page loads.   You simply need to create a form input (or div or td) to place the date.    In this case, using an input with the id time.

The basis of this solution is by kozaiwaniec on question http:Q_28001454.html#a38798846
0
 

Author Closing Comment

by:JimiJ13
ID: 39739524
Thanks for the nice client time. I just made a separate request here for the final part: http://www.experts-exchange.com/Programming/Languages/.NET/Q_28325581.html
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
scanning dentists xray (the small ones) 3 45
Replace &lt; with < 14 57
Error in JQuery 5 39
How can I echo a PHP variable in AJAX function? 7 37
Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
The viewer will learn how to dynamically set the form action using jQuery.
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now