How to Use the Js time function getYear () _ javascript skills

Source: Internet
Author: User
The getYear () function is not recommended because it is incorrectly displayed in Firefox. Therefore, the getFullYear () function is recommended, next we will introduce in detail how to use the getYear function in different browsing scenarios. The getYear () function is not recommended a long time ago, because it is incorrectly displayed in Firefox, we recommend that you use the getFullYear () function.
Firefox does not support the innerText attribute. You need to change it to textContent to receive the message.
Then, attach 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;
// Test the browser version.
// 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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.