Solved

Get Client Time

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
This article discusses how to create an extensible mechanism for linked drop downs.
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…

760 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

23 Experts available now in Live!

Get 1:1 Help Now