Solved

Get Client Time

Posted on 2013-12-24
4
376 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Hi all! Recently there was EE question and the person wanted to have a multi-column textbox <div> selection, so as a first step to answer I provided a link but that was not complete with JavaScript selection, but had a good style sheet. So as a ques…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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…

830 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