Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    891
    Thanks
    174
    Thanked 102 Times in 102 Posts

    get year not working Google Chrome

    Hello all

    I have this code to write the year which works fine in ie ff but apparantly is not working in google chrome.

    I don't have chrome and so can't check can anybody tell me why chrome has an issue with it? What should I change to make it chrome compliant:-)


    In ie ff it displays 2012 correctly but in chrome i'm told it is showing 112 ro something like that.


    Code:
    Code:
    <script type="text/javascript">var curdate = new Date(); var year = curdate.getYear(); document.write(year)</script>

    any help very much appreciated

    LT
    "The greatest revenge is to accomplish what others say you cannot do."
    ~ Unknown

    I used to be indecisive, but now I'm not so sure.

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    3,020
    Thanks
    56
    Thanked 566 Times in 563 Posts
    hello lowtech,

    I am surprised you were getting the right year in firefox - I got 112 there as well. I note that getYear() is deprecated, but I assume it gives you how many years it has been since 1900.

    or something useful like that.

    I think getFullYear() is what you are after

  • Users who have thanked xelawho for this post:

    low tech (01-16-2012)

  • #3
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    891
    Thanks
    174
    Thanked 102 Times in 102 Posts
    Hi xelawho

    Thanks for that --- didn't know getYear was deprecated.

    Yeh ff was showing ok and usually for me if ff is ok and ie doesn't complain then i'm good hahaha

    will change it later today

    much appreciated

    LT
    "The greatest revenge is to accomplish what others say you cannot do."
    ~ Unknown

    I used to be indecisive, but now I'm not so sure.

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    getYear returns different results in different browsers because it isn't Y2K compliant. No attempt was made to make it compliant because it was deprecated with getFullYear replacing it in the late 1990s.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • Users who have thanked felgall for this post:

    low tech (01-16-2012)

  • #5
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    891
    Thanks
    174
    Thanked 102 Times in 102 Posts
    Hi felgal

    Thanks for the info

    I had that code lying around and I just used it while recently updating my site ---- it seemed fine in ie ff but was but was reported as not working correctly.

    LT
    "The greatest revenge is to accomplish what others say you cannot do."
    ~ Unknown

    I used to be indecisive, but now I'm not so sure.

  • #6
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Unfortunately there's lots of obsolete JavaScript still around - and even people still teaching how to write JavaScript for the 1990s (without telling their students that what they are teaching was outdated 10 or more years ago).
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #7
    Regular Coder low tech's Avatar
    Join Date
    Dec 2009
    Posts
    891
    Thanks
    174
    Thanked 102 Times in 102 Posts
    Hi all

    Updated site -- all's well now:-)

    ie ff and chrome

    many thanks

    LT
    "The greatest revenge is to accomplish what others say you cannot do."
    ~ Unknown

    I used to be indecisive, but now I'm not so sure.

  • #8
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,303
    Thanks
    203
    Thanked 2,562 Times in 2,540 Posts
    Quote Originally Posted by felgall View Post
    Unfortunately there's lots of obsolete JavaScript still around - and even people still teaching how to write JavaScript for the 1990s (without telling their students that what they are teaching was outdated 10 or more years ago).
    Stephen - tell us about it! Almost every week students post assignments and code here which are wildly out of date. I wonder how long teachers of law or medicine would survive if they taught such obsolete stuff? I have the idea that some people who teach Javascript are the rejects from other subjects and have been downgraded to RE or IT!

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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