SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Resident Boozehound simontheak's Avatar
    Join Date
    Jun 2003
    Location
    _root.europe.uk.london
    Posts
    965
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with date() function

    Hiya,

    All I'm trying to do is put the current date into a website that I'm currently working on. Here's the code I'm using:

    <script language="javascript">
    now=new Date()
    month=now.getMonth()+1
    today=now.getDate()
    year=now.getYear()

    current=today+"/"+ month+"/"+year
    document.write(current)
    </script>

    The only problem I'm experiencing is that the date is coming out as 3/6/105.

    Where is the "1" coming from in the year? How can I get rid of it??

    Thanks alot,

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Portsmouth UK
    Posts
    1,499
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd"
    >

    <
    html>

    <
    head>
      <
    title></title>
    </
    head>

    <
    body>
    <
    script language="javascript">
    now=new Date()
    month=now.getMonth()+1
    today
    =now.getDate()
    year=now.getFullYear(); // NOTE this Line

    current=today+"/"month+"/"+year
    document
    .write(current)
    </script>

    </body>

    </html> 


Bookmarks

Posting Permissions

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