Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 20-05-2009
Member
 
Join Date: May 2008
Posts: 372
How to use PHP get year in firefox ?

Hello,

I would use the getYear in FireFox, but it does not display correctly.

Code:
<html> 
<body> 
<script type="text/javascript"> 
var d = new Date () 
document.write ( "2005 -" + d.getYear ()) 
</ script> 
</ body> 
</ html>

Perfect in IE but in FireFox, nothing works (bad display).

Can anyone help me?

Thank you very much!
Reply With Quote
  #2  
Old 20-05-2009
Member
 
Join Date: May 2008
Posts: 249
Re: How to use PHP get year in firefox ?

Did you think of those who have javascript disabled?

Your site should work well without javascript. The javascript in my opinion just to serve retail, to make something nice (like holding a CSS) and should not be essential for the proper functioning of your site.
Reply With Quote
  #3  
Old 20-05-2009
Member
 
Join Date: May 2008
Posts: 376
Re: How to use PHP get year in firefox ?

You should be use getFullYear () instead of getYear ();

Before 2000, getYear () returned 98 for 1998. Firefox has therefore continue as follows: 1999 = 99 and therefore 2000 = 100 2001 = 101 ... etc

Javascript is very useful and it depends on what tests you do.
getFullYear () you will return in 2006 in Firefox and IE ...

or you can use getYear () and simply add 1900 if necessary:
var d = new Date ();
var year = d.getFullYear ();

Code only for the year:

Code:
Date.prototype.getTwoDigitYear = function () {return /(\d{2})$/.test (this.getFullYear()) ? RegExp.$1 : this}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to use PHP get year in firefox ?"
Thread Thread Starter Forum Replies Last Post
Will the Serious Sam 3: BFE be the best game of the year? PurviJ Video Games 8 27-11-2011 06:47 PM
Download Firefox Aurora, Firefox Nightly and Firefox Beta Johnny Web News & Trends 1 21-08-2011 05:02 PM
Firefox Announces Firefox 6 Beta and Firefox 7 Aurora Eseld Technology & Internet 5 20-07-2011 07:48 PM
How to write a program to determine if year is leap year or not Luis-Fernando Software Development 4 30-11-2009 05:21 PM
How to get out of 2 year contract with AT&T Zacharia Portable Devices 3 24-08-2009 06:10 PM


All times are GMT +5.5. The time now is 04:05 AM.