Display current time on aspx page

Posted on 2006-07-21
Last Modified: 2012-06-21
I need to display the current date and time on an aspx webform.   I dont know anything abut javascript and hoping someone can help me.

I need to display the date and time, both in the long format: "Friday July 21, 2006 8:00:01 am"

Can somebody lend me some sample code?

Question by:Mike_Stevens
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
LVL 23

Expert Comment

ID: 17154143
Hi Mike_Stevens,

This might help:

you might need to edit slightly

LVL 23

Expert Comment

ID: 17154147
Here is another useful page about date formatting:
LVL 29

Accepted Solution

Pravin Asar earned 250 total points
ID: 17154322
These few lines of code will do the job.

<script language="javascript">
function printCurrentTime () {
documen.write ((new Date()).toString());

<div>Current Time : <script language="javascript">printCurrentTime();</script></div>
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.


Author Comment

ID: 17155167
The works fine to display the date but i was hoping to have it click off the seconds on the page
LVL 19

Assisted Solution

nschafer earned 250 total points
ID: 17155694
Hi Mike_Stevens,

Building on pravinasar's code:

<script language="javascript">
function printCurrentTime () {
document.getElementById("time").innerHTML = "Current Time: " + new Date().toString();
<div id="time"></div>

Hope this helps,
LVL 29

Expert Comment

by:Pravin Asar
ID: 17155708
To display second,

use this one
<script language="javascript">
function printCurrentTime () {
document.write ((new Date()).toLocaleString());

<div>Current Time : <script language="javascript">printCurrentTime();</script></div>


Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
Use Mid in Html 6 23
javascript form - error when hitting enter 3 28
Add somewhat of a wildcard to your javascript 12 31
Boolean 13 28
This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

696 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