Date Functions

The date functions in Dojo are like those little wrapped mints on your pillow. Surprising, little and fabulous!

/* GeSHi (C) 2004 - 2007 Nigel McNie (http://qbnz.com/highlighter) */ .geshifilter {font-family: monospace;} .geshifilter .imp {font-weight: bold; color: red;} .geshifilter .kw1 {color: #b1b100;} .geshifilter .kw2 {color: #000000; font-weight: bold;} .geshifilter .kw3 {color: #000066;} .geshifilter .coMULTI {color: #808080; font-style: italic;} .geshifilter .es0 {color: #000099; font-weight: bold;} .geshifilter .br0 {color: #66cc66;} .geshifilter .st0 {color: #ff0000;} .geshifilter .nu0 {color: #cc66cc;} .geshifilter .sc0 {color: #00bbdd;} .geshifilter .sc1 {color: #ddbb00;} .geshifilter .sc2 {color: #009900;}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
            "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Date Examples</title>
        <script type="text/javascript"
                src="http://o.aolcdn.com/dojo/1.0.0/dojo/dojo.xd.js">
</script>
        <script type="text/javascript">
           dojo.require("dojo.date");
           dojo.require("dojo.date.stamp");
          
       dojo.addOnLoad(function(){
           // We'll demonstrate these functions on today's date, so you'll have to think
           // for a minute to verify the functions work!
           var today = new Date();
           console.debug("today is "+today);
           
           // Is this year a leap year?
           console.debug("leap year: "+dojo.date.isLeapYear(today));
           
           // How many days in this month?
           console.debug("days in month: "+dojo.date.getDaysInMonth(today));
           
           // Convert to/from ISO format
           var dojo0_9Release = dojo.date.stamp.fromISOString("2007-08-20");
           
           // Do some arithmetic. 
           console.debug(
               dojo.date.difference(dojo0_9Release, today)+
               " days since Dojo 0.9 release"
           );
           
           var oneYearAnniversary = dojo.date.add(dojo0_9Release,"year",1);
           var isOneYearYet = dojo.date.compare(oneYearAnniversary, today);
           if (isOneYearYet > 0) {
                   console.debug(
                       dojo.date.difference(today, oneYearAnniversary)+
                       " days until one year anniversary of 0.9 release"
                   );
               }
           
       });
   </script>
</head>
</html>