0
A
回答
-1
var weekdays = [ "Sun", "Mon", "Tue", "Wed", "Thurs", "Fri", "Sat" ];
function getDateForLastOccurence(strDay)
{
var date = new Date();
var index = weekDays.indexOf(strDay);
var difference = date.getDay() - index;
if (difference < 0)
{
difference = -7 - difference;
}
date.setDate(date.getDate() + difference);
return date;
}
getDateForLastOccurence("Tue");
getDateForLastOccurence("Thurs");
0
首先,它會更容易通過共享代碼來幫助你;)
您可以通過使用該方法Date.getDay()
其返回一週的當天上週四得到。
像這樣:
var now = new Date();
var daysAfterLastThursday = (-7 + 4) - now.getDay(); // 7 = number of days in week, 4 = the thursdayIndex (0= sunday)
var currentMs = now.getTime();
var lastThursday = new Date(currentMs + (daysAfterLastThursday * 24 * 60 * 60 * 1000));
alert("Last Thursday : " + lastThursday);
0
簡單的,你可以自己做。
- 查找當前日d
- 由3
- 國防部步驟2的結果,通過使用7添加d(結果%7)
- 如果步驟3的結果是0減去7從今天的日期,否則從今天的日期中減去第3步的結果。
相關問題
- 1. 獲取該年度每個星期四的日期Javascript
- 2. 需要獲取python中給定月份的上個星期四的日期嗎?
- 3. JavaScript認爲星期四和星期五?
- 4. 獲取上週五並獲取下一個星期四
- 5. 獲取指定日期的星期日
- 6. 獲取星期數從一個星期的日期開始
- 7. PHP獲取這個星期的日期星期一
- 8. 獲取從給定日期星期一到星期五的星期日期
- 9. 每個星期四啓用日期,但禁用某些星期四
- 10. 在整個星期的基礎日期中獲取星期編號基於javascript
- 11. 獲取基於給定日期的星期一至星期日
- 12. 下一個星期四的日子
- 13. Android顯示從一週到另一週的日期(星期四至星期四)
- 14. 獲取上一個星期一的日期
- 15. 指定日期的獲取星期數
- 16. Informatica - 獲取星期一的日期號
- 17. SQL上週獲取間隔(星期日到星期六)
- 18. 獲取在Javascript一個星期的日子裏,周開始於星期天
- 19. 從Python的日期列獲取周開始日期(星期日)
- 20. 如何計算當前日期前四個星期日的日期
- 21. 在SQL中使用今天的日期獲取星期日期(星期一)
- 22. 獲取星期日期範圍內的天數,JavaScript的
- 23. 根據我們輸入的日期獲取最後3個星期四的日期
- 24. 獲取日期2星期一前
- 25. 從sql日期獲取星期
- 26. 在IOS SDK中獲取星期日期
- 27. 使用星期幾獲取日期
- 28. 根據星期編號獲取日期
- 29. 使用星期幾獲取日期
- 30. 獲取本週的開始日期和結束日期(星期一從星期一開始,星期日結束)
雖然我討厭成爲「那個人」,但到目前爲止你還有什麼嘗試? –
你應該看看JavaScript中的Date對象API,看看你得到了多少。 https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date – ToastyMallows
找到當天並從今天減去'currentDay + 3' – Rajesh