Solved

Get Client Time

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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…

808 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