什麼是常見方法,以獲得當前日曆周actionscript-3?獲取當前日曆周
Q
獲取當前日曆周
0
A
回答
1
重新設置問題以便您可以獲得當年的日期編號可能是個好主意,如果必須的話,您可以將其用於更多基於日期的計算。這是最容易與INTS的靜態數組和位運算的做...
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日或日曆星期開始的定義今年的第一個星期天?
- 你對一年中的閒暇時間,特別是閏年做什麼? (52x7!= 365)
- 您對日曆或財政年度感興趣嗎?
- 一年的每週定義是否相同?有時聖誕節有兩個星期或一個多月!
我結束了爲財務日曆和常規日曆編寫基於日期的算術函數庫。如果您在用戶擁有自己版本的日曆的任何環境中工作,即任何財務應用程序,這都是一個棘手的問題。
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;
+0
我想你錯了,currentDateDay == 0實際上是星期天 – 2013-10-07 10:08:49
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
1
或者讓你的手在org.casalib.util.DateUtil
和使用方法getWeekOfTheYear(d:Date):uint
。
相關問題
- 1. Android日曆獲得當前周,前幾周和下週
- 2. 從當前日期()中獲取日曆周的開始位置
- 3. 獲取當前週日和週日以前的日期
- 4. YUI日曆:獲取當前頁面/ pageChangedEvent
- 5. Android日曆:獲取下週的日子
- 6. YUI 2.0日曆 - 如何獲取當前日曆頁面
- 7. SQLite:獲取當前周
- 8. Bootstrap日曆控件在當前顯示的當前周活動?
- 9. 獲取前,當前和未來幾周不包括週六和週日
- 10. 想要從android中的日曆只獲得當前周事件?
- 11. 跳過週六和週日,並從ASP.NET中的當前日期獲取日期?
- 12. MySQL:如何使用當前日期獲取「本週的日期」?
- 13. 參考當前日期獲取一週中的日期數組
- 14. 在android中獲取當前茱利安日曆編號與公曆日曆
- 15. 很熱從Google日曆使用PHP獲取當前日期?
- 16. 如何在日曆中獲取當前工作日
- 17. 從當前日曆月和未來11個月獲取日期
- 18. 查看日期是否在同一個日曆周或前一個日曆周
- 19. 獲取提前一週的日期
- 20. java日曆 - 獲取最後5天的一週(沒有周末)
- 21. PHP的mysql_query - 獲取本週的行與當前日期
- 22. 如何在psql中獲取當前月份週日的數量?
- 23. 獲取當週的預約日期
- 24. 週末日曆
- 25. WPF日曆周
- 26. 谷歌日曆API得到當前一週
- 27. 在RichFaces日曆中突出顯示當前周
- 28. Jquery完整的日曆 - 只獲取當前的查看事件
- 29. 如何獲取所有當前的安卓日曆實例
- 30. 如何從Google日曆API獲取當前事件?
您是否試圖獲得本週的日期範圍(週日@12:00-週六@ 11:59 PM)或週數? – 2010-06-12 14:49:48
這已經在這裏回答http://stackoverflow.com/questions/2362956/flex-how-to-get-week-of-year-for-a-date/2363000#2363000 – Amarghosh 2010-06-14 10:50:57