www.webdeveloper.com
Results 1 to 3 of 3

Thread: Need new pair of eyes

Hybrid View

  1. #1
    Join Date
    Jun 2012
    Posts
    4

    Need new pair of eyes

    I'm new to JS so, please bear with me.
    I'm playing/learning with dates and time functions. Somehow, I got stuck here. I can't see why it isn't working. It is a very simple code. Here is the HTML:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Testing</title>
    <script type="text/javascript" src="scripts/jquery-1.6.3.min.js"></script>
    <script type="text/javascript" src="scripts/displayTime.js"></script>
    </head>
    <body>
    <h2>Displaying Date & Time</h2>
    <p>Today's Date is:
    <strong>
    <script type="text/javascript">
    document.write(printDate());
    </script>
    </strong></p>
    <p>The time is:
    <strong>
    <script type="text/javascript">
    document.write(printTime());
    </script>
    </strong></p>
    </body>
    </html>

    and the JS file "displayTime.js" in a separated folder:

    function printDate() {
    var month,today,year,mydate;
    var now = new Date();
    month = now.getMonth();
    today = now.getDate();
    year = now.getFullYear();
    mydate = month + "/" + date + "/" + year;
    return mydate;
    }

    function printTime() {
    var hours,minutes,seconds,time;
    var now = new Date();
    hours = now.getHours();
    minutes = now.getMinutes();
    if (minutes<10) {
    minutes = '0' + minutes;
    }
    seconds = now.getSeconds();
    if (seconds<10) {
    seconds = '0' + seconds;
    }
    time = hours + ":" + minutes + ":" + seconds;
    return time ;
    }

    I got this output(copy & paste):

    Displaying Date & Time

    Today's Date is:

    The time is: 18:39:51

    Could you please help me understand why the date is not showing?
    Thanks in advance

  2. #2
    Join Date
    May 2004
    Location
    Manhattan NY
    Posts
    6,028
    function printDate() {
    var month,today,year,mydate;
    var now = new Date();
    month = now.getMonth();
    today = now.getDate();
    year = now.getFullYear();
    mydate = month + "/" + today + "/" + year;
    return mydate;
    }

    you put "date" in there which was never defined.

  3. #3
    Join Date
    Jun 2012
    Posts
    4
    Thank you JPnyc,
    Just what I needed. I gess I need to buy a new pair of reading glasses

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles