Solved

Get Client Time

Posted on 2013-12-24
4
378 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 53

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 53

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

How To Reduce Deployment Times With Pre-Baked AMIs

Even if we can't include all the files in the base image, we can sometimes include some of the larger files that we would otherwise have to download, and we can also sometimes remove the most time-consuming steps. This can help a lot with reducing deployment times.

Question has a verified solution.

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

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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

622 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