在actionscript-3中获取当前日历周的常用方法是什么?
答案 0 :(得分:1)
重新制作问题可能是一个好主意,这样您就可以获得当年的日期编号,如果必须的话,您可以将它用于更多基于日期的计算。使用静态的int数组和一些算术运算最容易做到......
public static var month_days:Array = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
public static day_num(Date d):int
{
var cumulative_days:int = 0;
for (int i = 0; i < d.month; i++)
{
cumulative_days += month_days[i];
}
cumulative_days += d.date;
if (add_leap_day(d)) cumulative_days++;
return cumulative_days;
}
public static week_num(Date d):int
{
var int day_num = day_num(d);
return Math.floor(day_num/7);
}
public static function add_leap_day(Date d):boolean
{
// I'll let you work this out for yourself
// bear in mind you don't just need to know whether it's a leap year...
}
小心一些事情:
我为财务和常规日历编写了一整套基于日期的算术函数库。如果您在用户拥有自己的日历版本的任何环境中运行(即任何财务应用程序),这是一个棘手的问题。
答案 1 :(得分:1)
或者开始org.casalib.util.DateUtil
并使用方法getWeekOfTheYear(d:Date):uint
。
答案 2 :(得分:0)
这是另一个返回当前周的开始日期的函数:
public static function getDayCount(year:int, month:int):int
{
var d:Date = new Date(year, month + 1, 0);
return d.getDate();
}
public static function getThisWeekStartDate(date:Date):Date
{
var weekStartDate:Date;
var currentDateDay:Number = date.day;
if(currentDateDay == 0)
{
weekStartDate = new Date(date.fullYear, date.month, date.date);
}
else
{
var sDate:Number = date.date - currentDateDay;
if(sDate < 0)
{
var newWeekStartDate:Number = sDate + getDayCount(date.fullYear, date.month);
weekStartDate = new Date(date.fullYear, date.month-1, newWeekStartDate);
}
else
{
weekStartDate = new Date(date.fullYear, date.month, sDate);
}
}
return weekStartDate;
}
您可以通过以下方式获得结束日期:
var endDate:Date = new Date(startDate.fullYear, startDate.month, startDate.date);
endDate.date += 6;
答案 3 :(得分:0)
var today:Date = new Date();
var sunday:Date = new Date(today.fullYear, today.month, today.date - today.day);
var saturday:Date = new Date(sunday.fullYear, sunday.month, sunday.date + 6);
trace(sunday);
trace(saturday);
//Sun Oct 26 00:00:00 GMT+0800 2014
//Sat Nov 1 00:00:00 GMT+0800 2014