Login   Register  
Icontem

File: examples.txt

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Stephen Chapman  >  Extended Date  >  examples.txt  >  Download  
File: examples.txt
Role: Example script
Content type: text/plain
Description: Examples
Class: Extended Date
Manipulate and format dates and times
Author: By
Last change: expanded example of toCalendar with callback
Date: 2013-01-31 01:23
Size: 1,097 bytes
 

Contents

Class file image Download
// Display today'd date nicely formatted
var today = new extDate();
alert(today.format('jS F, Y - g:i:s a'));

// add 15 days to a date
var today = new extDate();
today.addDays(15);
alert(today.format('jS F, Y'));

// business days so far this year
var today, lastyear;
today = new extDate();
lastyear = new extDate(today.getFullYear()-1,11,31);
alert(today.busDayDiff(lastyear));

// current age
var today, dob;
today = new extDate();
dob = new extDate(1950, 6, 5); // assuming the person was born on 5th July 1950
alert(today.ageLastBirthday(dob));

// insert a calendar for December 2012 into the element with id="cal"
var d = new extDate(2012,11,25);
document.getElementById('cal').appendChild(d.toCalendar());


// insert a calendar for December 2012 into the element with id="cal"
// and call a callback function that alerts a message and the date

var setDate(y,m,d,msg) {alert(msg+(m+1)+'/'+d+'/'+y)'};
var d = new extDate(2012,11,25);
document.getElementById('cal').appendChild(d.toCalendar(setDate,'Today is '));

This will display "Today is 12/25/2012".