Results 1 to 3 of 3

Thread: How to get Current year with javascript

  1. #1
    Join Date
    May 2009
    Posts
    51

    How to get Current year with javascript

    I want write a code where i can get the current year.I have asked about the same to my friends too they told me that it's possible with javascript but don't know what would be the code for the same.Anyone over here can provide me code for getting current year.

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Get Current year with javascript

    Try to use the following code for getting Current year by using javascript

    Code:
    <script type="text/javascript">
    <!--
    
    var m_names = new Array("January", "February", "March", 
    "April", "May", "June", "July", "August", "September", 
    "October", "November", "December");
    
    var d = new Date();
    var curr_date = d.getDate();
    var curr_month = d.getMonth();
    var curr_year = d.getFullYear();
    document.write(curr_date + "-" + m_names[curr_month] 
    + "-" + curr_year);
    
    /* The last two lines above have 
    to placed on a single line */
    
    //-->
    </script>

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Print Current year with javascript

    If you want to get current year following are the code for the same
    Code:
    <script type="text/javascript">
    
    var brn = new Date("July 21, 2009 01:17:00");
    document.write("I was born in " + brn.getYear());
    var da = new Date();
    document.write(da.getYear());
    
    </script>

Similar Threads

  1. Help in finding the current day of the year in PHP
    By Karsenman in forum Software Development
    Replies: 5
    Last Post: 23-01-2010, 10:14 AM
  2. Online threats for the current year
    By Aandaleeb in forum Networking & Security
    Replies: 5
    Last Post: 13-01-2010, 12:22 AM
  3. How to write a program to determine if year is leap year or not
    By Luis-Fernando in forum Software Development
    Replies: 4
    Last Post: 30-11-2009, 05:21 PM
  4. How to find out Current Page Url with the help of JavaScript?
    By Kushan in forum Software Development
    Replies: 3
    Last Post: 21-11-2009, 10:40 AM
  5. How to get current directory
    By Scott2580 in forum Software Development
    Replies: 3
    Last Post: 11-10-2008, 03:40 PM

Tags for this Thread

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
  •  
Page generated in 1,751,765,733.16921 seconds with 16 queries