Programming: adding today’s date to a static web page

Stick this snippet into the code for your page.

JavaScript: The Good Parts
JavaScript: The Definitive Guide

Related Posts:

This entry was posted in Programming and tagged , , , , . Bookmark the permalink.

7 Responses to Programming: adding today’s date to a static web page

  1. Calophi says:


    document.write will kill any page that is being served as xml, which includes xhtml pages in many cases.

    Take a peek here for other options and further explanations:

    • Calophi says:

      Though frankly, that’s pretty clunky. Usually I have jquery in my sites anyway so I’d just use one of their manipulation methods to stick a date where I wanted it to go.

    • admin says:

      Interesting. I had not given it any thought before. (Of course, most of my development is desktop GUI and web backend, rather than front end) The particular use case this was from a demo site, loaded from disk rather than a server, that needed current dates for use as a presentation demo. A “work-alike” for a site that would later be served, and in that case the date would be piped into the output by the php that rendered the page.
      The suggestion from that blog post is interesting, using the script tag as a DOM reference for injecting the string. Elegant. Mine is just a quick and dirty hack to make suits happy. 🙂

    • admin says:

      One other thing… is xhtml deprecated in favor of HTML5?

      • Calophi says:

        I don’t think it’s deprecated. It might be updated to accommodate the new HTML5 tags, though.

        Basically XHTML is stricter HTML code, forcing people to clean up their code. When you write an XHTML page, you are basically writing XML but with a pre-defined set of tags so that you don’t have to sit there and define your own tags and style them with XSLT which is a HUGE pain in the arse. XHTML documents are supposed to be served as XML (IE6 and 7 don’t, because they’re stupid).

        I wouldn’t be surprised if, once HTML5 is implemented in more browsers, XHTML is updated to 2.0.

      • Calophi says:

        An article just came out that has a section not specifically dedicated to HTML vs XHTML, but has enough in it that you will be able to see why they’ll have to update XHTML.

        • admin says:

          So, it sounds like a conformist like me should probably be writing XHTML5 in most of his stuff. I mean, I want the DOM generated according to my desires… not whatever the browser thinks I might want. Plus, I like XML.