Return to Snippet

Revision: 28365
at July 7, 2010 07:54 by IsoJon


Initial Code
var showNowDate : Boolean;
var today_date : Date = new Date();
var thismonth : uint = today_date.getMonth();
var mnth : Array = new Array( 'January','February','March','April','May','June','July','August','September','October','November','December' );
var date_str : String = ( today_date.getDate()+" "+mnth[thismonth]+" "+today_date.getFullYear());

// displays current date in United States date format
trace(date_str);

// create sample text field
var dateTxt : TextField = new TextField();
addChild(dateTxt);

handleDate();

function handleDate() 
{
	var d = today_date.date;
	
	// replace these 'if statements' as needed.
	
	if ( d < 17 ) 
	{
		dateTxt.text = "Coming July 23";
	
	} else if ( d > 17 && d < 22 ) {
		dateTxt.text = "Coming Friday";
	
	} else if ( d == 22 ) {
		dateTxt.text = "Coming Tomorrow";
	
	} else {

		dateTxt.text = "Now!";
	}
}

Initial URL


Initial Description
Useful for event dates - looks at the computers clock and tells the user when something will be available (e.g. this friday, tomorrow, etc). In this example I'm just using the day of a month, but you can use any part/the full date if you desire. 

Help me make this snippet better!

Initial Title
Date Detector - Changes Date According to System Clock

Initial Tags
date

Initial Language
ActionScript 3