Year update for full (four digit) year or last two digits, with JavaScript


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. For full year (four digits):
  2.  
  3. JS:
  4.  
  5. today=new Date();
  6. y0=today.getFullYear();
  7.  
  8. HTML:
  9.  
  10. <p>&copy; <script type="text/javascript">document.write(y0);</script> Somecompany, Inc. All Rights reserved.</p>
  11.  
  12. - - - - -
  13.  
  14. For partial year (last two digits):
  15.  
  16. JS:
  17.  
  18. var foo = (new Date().getFullYear()).toString();
  19. // Contains last two characters of the full year.
  20. // ex: 2003 evaluates to 03.
  21. var bar = foo.substring(foo.length, 2);
  22.  
  23. HTML:
  24.  
  25. <p>All contents &trade; and &copy; 2005-<script type="text/javascript">document.write(bar);</script> Somecompany, Inc. unless otherwise noted herein. All rights reserved.</p>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.