Artemix
Artemix

Reputation: 8655

Determining the amount of days considering the current year in progress

I have to determine the amount of days based on the following data I receive from an XML:

The number is the amount that should be multiplied by the code, the code can vary in the following way:

1- days 2- weeks 3- months 4- semi-years 5- years

This means, if the code is 1, I show the number, if the code is 2, I show the number multiplied by 7.

The problem comes, when the code is 3, 4 or 5, since not all months have 30 days, nor all years have 365 days either.

Do you know of any way to do this in AS3?, maybe a timer function or something.

Thanks.

Upvotes: 1

Views: 47

Answers (1)

Andrey Popov
Andrey Popov

Reputation: 7510

The best way is to create a Date object. It has all the properties you need - days, weeks, months, years, hours, everything. There you can adjust them, by simply adding:

var date:Date = new Date();
date.days += 51;
trace (date);

Note that this is a sample - look at the reference for the things you need.

This is the best option, as Flash will automatically calculate everything for you. Even if you add 51 days, it will actually increase by one month, and based on the current month it will calculate how much days to add for the next month. You won't need to deal with any math :)

Upvotes: 1

Related Questions