15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

232<br />

<strong>JavaScript</strong> <strong>Examples</strong> <strong>Bible</strong>: The Essential Companion to <strong>JavaScript</strong> <strong>Bible</strong><br />

fgColor<br />

See alinkColor.<br />

fileCreatedDate<br />

fileModifiedDate<br />

fileSize<br />

document.fileCreatedDate<br />

NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5<br />

Compatibility ✓ ✓ ✓<br />

Example<br />

Listing 18-4 dynamically generates several pieces of content relating to the creation<br />

and modification dates of the file, as well as its size. More importantly, the listing<br />

demonstrates how to turn a value returned by the file date properties into a<br />

genuine date object that can be used for date calculations. In the case of Listing<br />

18-4, the calculation is the number of full days between the creation date and the<br />

day someone views the file. Notice that the dynamically generated content is added<br />

very simply via the innerText properties of carefully-located SPAN elements in the<br />

body content.<br />

Listing 18-4: Viewing File Dates<br />

<br />

<br />

fileCreatedDate and fileModifiedDate Properties<br />

<br />

function fillInBlanks() {<br />

var created = document.fileCreatedDate<br />

var modified = document.fileModifiedDate<br />

document.all.created.innerText = created<br />

document.all.modified.innerText = modified<br />

var createdDate = new Date(created).getTime()<br />

var today = new Date().getTime()<br />

var diff = Math.floor((today - createdDate) / (1000*60*60*24))<br />

document.all.diff.innerText = diff<br />

document.all.size.innerText = document.fileSize<br />

}<br />

<br />

<br />

<br />

fileCreatedDate and fileModifiedDate Properties<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!