/ Published in: ActionScript 3
                    
                                        
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!
                Help me make this snippet better!
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
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!";
}
}
Comments
 Subscribe to comments
                    Subscribe to comments
                
                