Nipuna
Nipuna

Reputation: 7026

Retrieve day when the date is given

When given the year, month and the date, I want to retreive the day the date belongs to. Is there a function available in ActionScript for this?

Input : 
Year : 2012
Month : 11
Date : 29

Output : Thursday

Upvotes: 0

Views: 86

Answers (2)

Sunil D.
Sunil D.

Reputation: 18194

If you want to get fancy, you can also output a day name that is specific to your user's locale:

        var d:Date = new Date(2012, 10, 29); // November 29, 2012
        trace ("The day of week (number) is: ", d.day); // outputs: The day of week (number) is:  4
        var f:DateTimeFormatter = new DateTimeFormatter( LocaleID.DEFAULT, DateTimeStyle.SHORT, DateTimeStyle.SHORT);
        f.setDateTimePattern("EEEE");
        trace(f.format(d)); // outputs: "Thursday"

EDIT:

I used the Flash class flash.globalization.DateTimeFormatter, but there are also Flex specific classes for this too.

Upvotes: 2

Nipuna
Nipuna

Reputation: 7026

Ok Finally I got it working. In Date() constructor it seems the index for the year and the day is the same but the month index should be -1;

//this returns Day of September 1st. Not August 1st.
var d:Date = new Date(2012,8,1); 
Alert.show(" "+d.day);

Upvotes: 0

Related Questions