- The Book of Dojo
- Quick Installation
- Hello World
- Debugging Tutorial
- Introduction
- Part 1: Life With Dojo
- Part 2: Dijit
- Part 3: JavaScript With Dojo and Dijit
- Part 4: Testing, Tuning and Debugging
- Part 5: DojoX
- The Dojo Book, 0.4
Date Functions
Submitted by criecke on Wed, 06/06/2007 - 21:24.
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>
"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>
- Printer-friendly version
- Login or register to post comments
- Subscribe post