Home > Web Front-end > JS Tutorial > Precautions for FireFox's getYear_javascript skills

Precautions for FireFox's getYear_javascript skills

WBOY
Release: 2016-05-16 19:15:50
Original
1110 people have browsed it

Last week, I was sorting out a calendar script I wrote before. There was always a problem with the year display under FF, which made me depressed. For example, the following script: prompts "2007" under IE - no problem! But under FF, it prompts "107"?


[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute it
]

Google it and you understand. FF's getYear returns the value of "current year -1900" (legend has always been done this way), while NB's MS treats Year>=2000 and directly adds back the subtracted 1900. Haha, I admire IE’s fault tolerance and capacity again^_^

The most direct solution is year = (year < 1900) ? (1900 year) : year;

Of course you have to There is no problem in judging the Browser type and then classifying it.

The most reasonable thing is to use getFullYear or getUTCFullYear to call getYear. You can change the corresponding code in the Code box above to see the effect.
<script> var today = new Date(); alert(today.getYear()); </script>
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template