Last active
February 27, 2016 01:50
-
-
Save yukihirai0505/5d23464ba18213628ead to your computer and use it in GitHub Desktop.
日付を扱う便利スクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
指定日を文字列で取得する | |
@param nDaysAgo 何日前か | |
@return date | |
**/ | |
function getLastNdays(nDaysAgo) { | |
var today = new Date(); | |
var before = new Date(); | |
before.setDate(today.getDate() - nDaysAgo); | |
return DateFormat(before); | |
} | |
/** | |
指定月の初日を文字列で取得する | |
@param nMonthAgo 何カ月前か | |
@return date | |
**/ | |
function getFirstDayOfMonth(date) { | |
date.setDate(1); | |
return DateFormat(date); | |
} | |
/** | |
指定月の最終日を文字列で取得する | |
@param nMonthAgo 何カ月前か | |
@return date | |
**/ | |
function getLastDayOfMonth(date) { | |
date.setDate(1); | |
date.setMonth(date.getMonth() + 1); | |
date.setDate(0); | |
return DateFormat(date); | |
} | |
/** | |
指定月を取得する | |
@param nMonthAgo 何カ月前か | |
@return date | |
**/ | |
function getLastNMonth(nMonthsAgo) { | |
var today = new Date(); | |
var before = new Date(); | |
before.setMonth(today.getMonth() - nMonthsAgo); | |
return before; | |
} | |
/** | |
日付けのフォーマット | |
@param date | |
@return date | |
**/ | |
function DateFormat(date) { | |
var formatType = 'yyyy-MM-dd'; | |
return Utilities.formatDate(date, 'JST', formatType); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment