- <script>
- var now = new Date();
- var nowDayOfWeek = now.getDay();
- var nowDay = now.getDate();
- var nowMonth = now.getMonth();
- var nowYear = now.getYear();
- nowYear += (nowYear < 2000) ? 1900 : 0;
-
-
- function formatDate(date) {
- var myyear = date.getFullYear();
- var mymonth = date.getMonth()+1;
- var myweekday = date.getDate();
- if(mymonth < 10){
- mymonth = "0" + mymonth;
- }
- if(myweekday < 10){
- myweekday = "0" + myweekday;
- }
-
-
-
- var myHour = date.getHours();
- var myMinute = date.getMinutes();
- var mySecond = date.getSeconds();
- if(myHour < 10){
- myHour = "0" + myHour;
- }
- if(myMinute < 10){
- myMinute = "0" + myMinute;
- }
- if(mySecond < 10){
- mySecond = "0" + mySecond;
- }
- return (myyear+"-"+mymonth + "-" + myweekday+" "+myHour+":"+myMinute+":"+mySecond);
- }
-
-
- function getMonthDays(myMonth){
- var monthStartDate = new Date(nowYear, myMonth, 1);
- var monthEndDate = new Date(nowYear, myMonth + 1, 1);
- var days = (monthEndDate - monthStartDate)/(1000 * 60 * 60 * 24);
- return days;
- }
-
-
- function getQuarterStartMonth(){
- var quarterStartMonth = 0;
- if(nowMonth<3){
- quarterStartMonth = 0;
- }
- if(2<nowMonth && nowMonth<6){
- quarterStartMonth = 3;
- }
- if(5<nowMonth && nowMonth<9){
- quarterStartMonth = 6;
- }
- if(nowMonth>8){
- quarterStartMonth = 9;
- }
- return quarterStartMonth;
- }
-
-
- function getDayStartDate(i) {
- var nowStartDay = new Date(nowYear, nowMonth, nowDay+i);
- return formatDate(nowStartDay);
- }
-
-
- function getDayEndDate(i) {
- var nowStartDay = new Date(nowYear, nowMonth, nowDay+i,23,59,59);
- return formatDate(nowStartDay);
- }
-
-
- function getWeekStartDate(i) {
-
- var weekStartDate = new Date(nowYear, nowMonth, nowDay - nowDayOfWeek+7*i);
- return formatDate(weekStartDate);
- }
-
-
- function getWeekEndDate(i) {
-
- var weekEndDate = new Date(nowYear, nowMonth, nowDay + (6 - nowDayOfWeek)+7*i,23,59,59);
- return formatDate(weekEndDate);
- }
-
-
- function getMonthStartDate(i){
-
- var monthStartDate = new Date(nowYear, nowMonth+i, 1);
- return formatDate(monthStartDate);
- }
-
-
- function getMonthEndDate(i){
-
- var monthEndDate = new Date(nowYear, nowMonth+i, getMonthDays(nowMonth+i,),23,59,59);
- return formatDate(monthEndDate);
- }
-
-
- function getQuarterStartDate(i){
-
- var quarterStartDate = new Date(nowYear, getQuarterStartMonth()+3*i, 1);
- return formatDate(quarterStartDate);
- }
-
-
- function getQuarterEndDate(i){
- var quarterEndMonth = getQuarterStartMonth()+3*i + 2;
-
- var quarterStartDate = new Date(nowYear, quarterEndMonth, getMonthDays(quarterEndMonth),23,59,59);
- return formatDate(quarterStartDate);
- }
-
-
- function getYearStartDate(i){
- var quarterStartDate = new Date(nowYear+i, 0, 1);
- return formatDate(quarterStartDate);
- }
-
-
- function getYearEndDate(i){
- var quarterStartDate = new Date(nowYear+i, 11, getMonthDays(11),23,59,59);
- return formatDate(quarterStartDate);
- }
-
- alert(getMonthStartDate(1));
- </script>