Login Register

Date Functions

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

<!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>