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

May 16, 2016 pm 05:38 PM
time function

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;
}
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use the time function in Go language to generate a schedule calendar and generate SMS reminders? How to use the time function in Go language to generate a schedule calendar and generate SMS reminders? Jul 30, 2023 pm 03:49 PM

How to use the time function in Go language to generate a schedule calendar and generate SMS reminders?

How to use time function in Go language to generate calendar and output to HTML file? How to use time function in Go language to generate calendar and output to HTML file? Jul 29, 2023 pm 06:46 PM

How to use time function in Go language to generate calendar and output to HTML file?

PHP time function example: comparison of time PHP time function example: comparison of time Jun 20, 2023 pm 09:04 PM

PHP time function example: comparison of time

How to use the time function in Go language to generate a schedule calendar and generate WeChat and email reminders? How to use the time function in Go language to generate a schedule calendar and generate WeChat and email reminders? Jul 30, 2023 pm 08:21 PM

How to use the time function in Go language to generate a schedule calendar and generate WeChat and email reminders?

How to use the time function in Go language to generate a schedule calendar and generate WeChat reminders? How to use the time function in Go language to generate a schedule calendar and generate WeChat reminders? Jul 30, 2023 am 10:09 AM

How to use the time function in Go language to generate a schedule calendar and generate WeChat reminders?

How to get the current time using the TIME function in MySQL How to get the current time using the TIME function in MySQL Jul 13, 2023 am 09:31 AM

How to get the current time using the TIME function in MySQL

How to use the time function in Go language to generate a schedule calendar and generate email reminders? How to use the time function in Go language to generate a schedule calendar and generate email reminders? Aug 02, 2023 pm 02:21 PM

How to use the time function in Go language to generate a schedule calendar and generate email reminders?

How to use the time function in Go language to generate a schedule calendar and generate SMS, email and WeChat reminders? How to use the time function in Go language to generate a schedule calendar and generate SMS, email and WeChat reminders? Jul 29, 2023 pm 02:29 PM

How to use the time function in Go language to generate a schedule calendar and generate SMS, email and WeChat reminders?

See all articles