Home > Web Front-end > JS Tutorial > Discussion on the use of Js time function getYear()_javascript skills

Discussion on the use of Js time function getYear()_javascript skills

WBOY
Release: 2016-05-16 17:38:44
Original
1145 people have browsed it

The getYear() function was deprecated a long time ago because it was displayed incorrectly in Firefox. It is recommended to use the getFullYear() function.
In addition, Firefox does not support the innerText attribute and needs to be changed to textContent to receive it.
Then attach the code

Copy the code The code is as follows:

var s,Sys = {},ua = window.navigator.userAgent.toLowerCase();
(s = ua.match(/msie ([d.] )/)) ? Sys.ie = s[1] :
( s = ua.match(/firefox/([d.] )/)) ? Sys.firefox = s[1] :
(s = ua.match(/chrome/([d.] )/)) ? Sys.chrome = s[1] :
(s = ua.match(/opera.([d.] )/)) ? Sys.opera = s[1] :
(s = ua. match(/version/([d.] ).*safari/)) ? Sys.safari = s[1] : 0;
//Browser version number for testing
//if (Sys.ie ) { document.write('IE: ' Sys.ie); }
//if (Sys.firefox){ document.write('Firefox: ' Sys.firefox);}
//if (Sys .chrome){ document.write('Chrome: ' Sys.chrome);}
//if (Sys.opera){ document.write('Opera: ' Sys.opera);}
//if (Sys.safari) { document.write('Safari: ' Sys.safari); }
var today = new Date();
var day,date;
if (today.getDay() = = 0) { day = "Sunday"; }
if (today.getDay() == 1) { day = "Monday"; }
if (today.getDay() == 2) { day = "Tuesday"; }
if (today.getDay() == 3) { day = "Wednesday"; }
if (today.getDay() == 4) { day = "Thursday"; }
if (today.getDay() == 5) { day = "Friday"; }
if (today.getDay() == 6) { day = "Saturday"; }
date = " Today is: " (today.getFullYear()) "Year" (today.getMonth() 1) "Month" today.getDate() "Day" day "";
if (Sys.firefox)
{
document.getElementById('time_id').textContent = date;
} else {
document.getElementById('time_id').innerText = date;
}
Related labels:
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