Posted By

IsoJon on 07/07/10


Tagged

date clock detector


Versions (?)

Date Detector - Changes Date According to System Clock


 / 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!

  1. var showNowDate : Boolean;
  2. var today_date : Date = new Date();
  3. var thismonth : uint = today_date.getMonth();
  4. var mnth : Array = new Array( 'January','February','March','April','May','June','July','August','September','October','November','December' );
  5. var date_str : String = ( today_date.getDate()+" "+mnth[thismonth]+" "+today_date.getFullYear());
  6.  
  7. // displays current date in United States date format
  8. trace(date_str);
  9.  
  10. // create sample text field
  11. var dateTxt : TextField = new TextField();
  12. addChild(dateTxt);
  13.  
  14. handleDate();
  15.  
  16. function handleDate()
  17. {
  18. var d = today_date.date;
  19.  
  20. // replace these 'if statements' as needed.
  21.  
  22. if ( d < 17 )
  23. {
  24. dateTxt.text = "Coming July 23";
  25.  
  26. } else if ( d > 17 && d < 22 ) {
  27. dateTxt.text = "Coming Friday";
  28.  
  29. } else if ( d == 22 ) {
  30. dateTxt.text = "Coming Tomorrow";
  31.  
  32. } else {
  33.  
  34. dateTxt.text = "Now!";
  35. }
  36. }

Report this snippet  

You need to login to post a comment.