Code of the Year
Like most people, I have difficulty writing my first cheque of the new year. I always write the wrong year. Apparently, I am also like most web sites.
Many big, respectable and seemingly well-maintained sites show a previous year in their copyright footer. Some are painfully out of date.
If this was something that must be done manually, I could understand. But the content on a web page is not written with a Bic Grip Roller. It’s generated by a computer that knows the current year.
Here’s some code you can use to keep your copyright current. Examples for Perl, Python, etc. are appreciated!
In Javascript:
<script language="javascript" type="text/javascript">
//<![CDATA[
var mydate = new Date();
var year= mydate.getYear();
if (year<2000){year+=1900};
if (year>2100){year-=1800};
var time = ( year );
document.write(time);
//]]>
</script>
In PHP:
<?php echo date("Y");?>
In parsed HTML (aka SHTML, must be enabled in Apache):
<!--#config timefmt=" %Y" --> <!--#echo var="DATE_LOCAL" -->
In Java (JSP, thanks to Tim!):
<%= (new SimpleDateFormat("yyyy")).format( new Date() ) %>
In Smalltalk (thanks to Tim!):
^Date today year asString
In Ruby (thanks to Scott Boms):
add the following to a helper (eg. application_helper)def copyright_year t = Time.now t.year end
then in the view file, just put <%= copyright_year %>
- Published:
- 2.22.07 / 9am
- Category:
- User Experience
-
2.22.07 /
8pm
In Django it’s:
{% now “Y” %}
-
1.2.08 /
5pm
Straight Python:
import datetime print datetime.date.today().yearIn Pylons:
${h.date.datetime.today().year}Of course it’s super-easy to make your own webhelpers so that they’re as short as
${h.year}. -
3.24.08 /
3pm
if the content of a page doesn’t change, then the copyright year shouldn’t either. if someone wants to challenge a copyright claim in court they can say the true date of the content can’t be determined.
Have your say
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
I get my kicks designing and testing the users’ experience of software. Notable projects include search interface designs for:
3 Comments
comments rss | trackback uri