4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JavaScriptでプレミアムフライデー(月末最終金曜日)の日付を取得してみた

Posted at

せっかくプレミアムフライデーなので。

月末最終金曜日の日付を取得する

第4週・5週の金曜日が月末をオーバーしてるかをチェックして判定してみました。

function get_premium_friday(year, month) {
	month -= 1;
	var date = new Date(year, month, 1);
	var weekday = date.getDay();
	
	var day_4week = new Date(year, month, 7*3 + 6 - weekday);
	var day_5week = new Date(year, month, 7*4 + 6 - weekday);
	var end_of_month = new Date(year, month + 1, 0);
	
	return (day_5week > end_of_month ? day_4week : day_5week);
}

実行と結果

for (var i = 1 ; i <= 12 ; i++) {
	console.log(get_premium_friday(2017, i));
}

/*
Fri Jan 27 2017 00:00:00 GMT+0900 (東京 (標準時))
Fri Feb 24 2017 00:00:00 GMT+0900 (東京 (標準時))
Fri Mar 31 2017 00:00:00 GMT+0900 (東京 (標準時))
Fri Apr 28 2017 00:00:00 GMT+0900 (東京 (標準時))
Fri May 26 2017 00:00:00 GMT+0900 (東京 (標準時))
Fri Jun 30 2017 00:00:00 GMT+0900 (東京 (標準時))
Fri Jul 28 2017 00:00:00 GMT+0900 (東京 (標準時))
Fri Aug 25 2017 00:00:00 GMT+0900 (東京 (標準時))
Fri Sep 29 2017 00:00:00 GMT+0900 (東京 (標準時))
Fri Oct 27 2017 00:00:00 GMT+0900 (東京 (標準時))
Fri Nov 24 2017 00:00:00 GMT+0900 (東京 (標準時))
Fri Dec 29 2017 00:00:00 GMT+0900 (東京 (標準時))
*/
4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?