Date and Time

The Date class is built-in to Flash. An instance of the Date is automatically initialized with the current date and time. The class has methods for retrieving the day, month, year, hours, seconds, and more. Get Adobe Flash player

  1. Start a new ActionScript 3 file.
  2. In the ActionScript window type the following:
var d:Date=new Date();

The output window will display a number for the month beginning with 0 for January, 1 for February, 2 for March, etc.

If we want to display the name of the month we must use an array, then display the name of the month from the array:

var d:Date=new Date();
var hour:int=d.hours;
var greeting:String;
if(hour<12) greeting="Good Morning!";
else if (hour<18) greeting="Good Afternoon!";
else greeting="Good Evening!";
var day: Array = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var dayNum:int=d.getDay();
lblDay.text="Today is "+day[dayNum];
var month: Array = new Array("January", "February", "March", "April", "May", "June","July", "August","September", "October", "November", "December");
var monthNum:int=d.getMonth();
lblDate.text=month[monthNum]+ " "", "+d.getFullYear();

Download the movie
You could also do this using a timer.

NEXT: A Digital Clock