回答
在我們的日曆組成部分,我們使用此代碼來計算在一週的第一天;我敢打賭它可能會被修改以查找本週的最後日期。它利用的DateUtils library
public static const DAY_OF_MONTH:String = "date";
/**
* This method gets the first date of the week which the given date is in.
*
* @param date This is the date for which we want to process.
* @param firstDayOfWeek The first day of the week, 0 (Sunday) - 6 (Saturday); 0 is the default. It will probably be used primarily for localization purposes.
*
* @return This returns a date representing the first day of the week.
*/
public static function firstDateOfWeek(date:Date, firstDayOfWeek : int = 0):Date {
var dayIncrement : int = dayOfWeekLocalized(date, firstDayOfWeek);
var returnDate : Date = DateUtils.dateAdd(DateUtils.DAY_OF_MONTH,-dayIncrement,date);
return returnDate;
}
/**
* This method returns the position of the day in a week, with respect to the firstDayOfWeek localization variable.
*
* If firstDayOfWeek is 0; then the week is display 0 (Sunday), 1 (Monday), 2 (Tuesday), 3 (Wednesday), 4 (Thursday), 5 (Friday), 6 (Saturday).
* So, a Sunday would return 0, a Saturday would return 6, and so on.
*
* If firstDayOfWeek is 1; then the week is displayed as 0 (Monday), 1 (Tuesday), 2 (Wednesday), 3 (Thursday), 4 (Friday), 5 (Saturday), 6 (Sunday).
* However, this situation will not change the date.day value. For display purposes we need a Sunday to return 6, a Saturday to return 5, and so on.
*
* This will presumably be used for display purposes.
*
* @param date This is the date to process.
* @param firstDayOfWeek The first day of the week, 0 (Sunday) - 6 (Saturday); 0 is the default. It will probably be used primarily for localization purposes.
*
* @return This returns a date representing the day’s location on the localized week display.
*/
public static function dayOfWeekLocalized(date:Date, firstDayOfWeek : int = 0):int {
var result : int = date.day - firstDayOfWeek;
if(result < 0){
result += 7;
}
return result;
}
要找到一個星期的最後一天,我懷疑你可以調用firstDateOfWeek和加6天數:
public static function lastDateOfWeek(date:Date, firstDayOfWeek : int = 0):Date {
var firstDateOfWeek : Date = firstDateOfWeek(date, firstDayOfWeek);
var returnDate : Date = DateUtils.dateAdd(DateUtils.DAY_OF_MONTH,6,firstDateOfWeek);
return returnDate;
}
注:第二批代碼爲用瀏覽器編寫,完全沒有經過測試。
更新: 給出一個具體的日期,你可以找到使用在DateUtils library的WEEKOFYEAR方法WEEKOFYEAR數。使用上述方法來找到周的第一個和最後一個日期問題
概念是這樣的:
var weekOfYear : Number = DateUtils.weekOfYear(myDate);
var firstDayOfWeek : Date = firstDateOfWeek(myDate);
var lastDayOfWeek : Date = lastDateOfWeek(myDate);
我this blog post處理過這個問題。這很簡單,真的。任何給定月份的最後一天比下個月的第一天少一天。如果最後一天不是星期六,則會有重疊。
原始海報想知道這個星期是否跨越了兩個月嗎?還是他想知道一週的實際最後一天是什麼?我還不清楚,這將回答第一個問題 – JeffryHouser 2012-07-10 17:39:10
問題的措辭使人很難知道...... – 2012-07-11 00:52:04
- 1. 計算重疊
- 2. 你如何計算重疊的rgba值?
- 3. 如何計算重疊區域?
- 4. 計算重疊分鐘的數量
- 5. 一年有52.17周。如何計算C#中的當前週數?
- 6. 計算Tensorflow中的邊界框重疊
- 7. 計算重疊RGBA值
- 8. 計算日期重疊
- 9. 下週如何計算?
- 10. 如何計算下週一?
- 11. NPP:重疊計算和數據傳輸
- 12. 如何計算週期性數字?
- 13. 如何根據日期計算「週數」?
- 14. 如何計算一週數corona sdk?
- 15. 計算如果圓重疊矩形
- 16. 有周數如何計算一週的最後一天?
- 17. 如何計算mysql中的每週數據的月度數據
- 18. 在mysql中計算重疊按位列
- 19. 如何在Flex中計算10^5
- 20. Flex中的年齡計算
- 21. Flex中的數據包丟失計算
- 22. 計算一週中的日期數
- 23. 計算CUDA內核中的週期數
- 24. 計算一年中的週數(0-53)
- 25. javascript計算從週數
- 26. 按日期計算週數
- 27. 計算組之間的重疊
- 28. 計算兩條平行線的重疊
- 29. 按周計算
- 30. 計算周
我不確定你想要計算重疊週數。你只是想給一個約會嗎?然後「輸出」一週的最後一天?(星期六?) – JeffryHouser 2012-07-10 16:34:32
不僅僅是日期,需要顯示一週的數字以及一個月的日期。例如,7月29日至7月31日的第38周是2012年7月的月份。然而,2012年8月1日到8月4日也進入同一周的數字,即38。所以這些日期是重疊的,因爲它們屬於2個不同的月份 – flex 2012-07-10 19:49:01
我修改了我的答案,有關如何獲得weekOfYear,該周的第一個日期和這一週的最後一天 – JeffryHouser 2012-07-10 20:22:09