|
This is an excellent example of how pages are generated dynamically by ASP. Look at the HTML source (use View/Source in Internet Explorer) and all that you'll see is the date as if the HTML was written that way. And that's exactly what's happened in fact, but rather than me writing the HTML in my editor, my ASP page has.
Source code Date.asp<!--#include file = "include/Startup.asp"-->
<% // ============================================ // NOTE: all source code downloaded from CoverYourASP was written by // James Shaw (unless stated otherwise), and is copyright (c) 2000-2002 // by James Shaw. You can use the code for any purpose, but do not // publish or distribute the content in any way. // // See http://CoverYourASP.com/Legal.asp for up-to-date details. // ============================================
// output relevant meta tags Init( "Dynamic content - the time!" );
// output common top of page Header( 'Dynamic content' );
// output page content Content ( );
// output common bottom of page Footer( );
// ============================================ // the content of this page // ============================================ function Content ( ) { Out ( '<td valign="top" class="content">' );
Out ( '<b>' + GetDate ( ) + '</b>' );
Out ( '<p>This is an excellent example of how pages are generated dynamically by ASP. Look at the HTML source (use View/Source in Internet Explorer) and all that you\'ll see is the date as if the HTML was written that way.' );
Out ( '<p>And that\'s exactly what\'s happened in fact, but rather than me writing the HTML in my editor, my ASP page has.' ); Out ( '<p>You can see my actual ASP source code by clicking on the icon below.' );
Out ( '<p><center><a href="ShowSource.asp?page=Date"><img src="images/source.gif" border=0></a></center>' );
ShowBottomBanner()
Out ( '</td>' ); Out ( '<td background="images/gx/navgap.gif" valign="top">' );
// show rotating banners ShowBanners ( 1 );
Out ( '</td>' ); }
// ============================================ // returns a formatted string containing todays time and date // ============================================ function GetDate ( ) { var dateToday = new Date(); var sDays = new Array ( "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" );
var sDate = 'Here in Atlanta it\'s ' + sDays[dateToday.getDay()] + ", ";
// work out which suffix to append var nDate = dateToday.getDate(); var nMod = nDate % 10; var sSuffix = "th";
if ( nDate < 10 || nDate > 20 ) { if ( nMod == 1 ) sSuffix = "st"; else if ( nMod == 2 ) sSuffix = "nd"; else if ( nMod == 3 ) sSuffix = "rd"; }
// note: don't bother adding <SUP> to the suffix - it's too small sDate += nDate + sSuffix + " ";
var sMonths = new Array ( "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" );
sDate += sMonths[dateToday.getMonth()];
// now the time.. sDate += ' at ';
if ( dateToday.getMinutes() < 7 ) sDate += 'just after'; else if ( dateToday.getMinutes() < 22 ) sDate += 'quarter past'; else if ( dateToday.getMinutes() < 37 ) sDate += 'half past'; else { dateToday.setHours ( dateToday.getHours () + 1 );
if ( dateToday.getMinutes() < 52 ) sDate += 'quarter to'; else sDate += 'just before'; }
sDate += ' ';
if ( dateToday.getHours () == 0 ) sDate += 'midnight'; else if ( dateToday.getHours () < 12 ) sDate += dateToday.getHours () + ' in the morning'; else if ( dateToday.getHours () == 12 ) sDate += 'midday'; else if ( dateToday.getHours () < 18 ) sDate += (dateToday.getHours () - 12) + ' in the afternoon'; else sDate += (dateToday.getHours () - 12) + ' at night'; sDate += '. (ish)';
return sDate; } %> From coveryourasp.com |