Skip to content

Instantly share code, notes, and snippets.

@collegeman
Created April 30, 2010 02:17
Show Gist options
  • Save collegeman/384624 to your computer and use it in GitHub Desktop.
Save collegeman/384624 to your computer and use it in GitHub Desktop.
smoke-alarm-expiration-jquery.js
<script type="text/javascript">
jQuery(function() {
// now
var now = new Date();
// January 1 of this year
var jan = new Date(now.getFullYear(), 0, 1, 0, 0, 0, 0);
// seconds into year
var date = now.getTime()-jan.getTime();
// ten years ago
var d = new Date(now.getFullYear()-10, 0, 1, 0, 0, 0, date);
// format the date
var mon = ['January','February','March','April','May','June','July','August','September','October','November','December'][d.getMonth()];
var day = d.getDate();
var year = d.getFullYear();
var formatted = mon + ' ' + day + ', ' + year;
// a URL for linking
var url = 'http://www.google.com/products?q=smoke+detector&hl=en&aq=f';
// replace the text
jQuery('.your_css_class').html(
'If you bought your smoke detector before ' +
'<span class="the_date">' + formatted + '</span>, ' +
'it needs to be <a href="' + url + '">replaced</a>.'
);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment