"함수 next month()"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-source +syntaxhighlight))
 
(다른 사용자 한 명의 중간 판 4개는 보이지 않습니다)
1번째 줄: 1번째 줄:
[[분류: 월]]
{{DISPLAYTITLE:함수 next_month()}}
{{DISPLAYTITLE:함수 next_month()}}
==개요==
==개요==
5번째 줄: 6번째 줄:
==JavaScript==
==JavaScript==
[[분류: JavaScript]]
[[분류: JavaScript]]
<source lang='javascript'>
<syntaxhighlight lang='javascript'>
var d = new Date("2019-07");
var d = new Date("2019-07");
d.setMonth(d.getMonth() + 1);
d.setMonth(d.getMonth() + 1);
console.log( d.toISOString().substr(0,7) );
console.log( d.toISOString().substr(0,7) );
// 2019-08
// 2019-08
</source>
</syntaxhighlight>
<source lang='javascript'>
<syntaxhighlight lang='javascript'>
var mon = "2019-07";
var mon = "2019-07";
var d = new Date();
var d = new Date();
18번째 줄: 19번째 줄:
console.log( d.toISOString().substr(0,7) );
console.log( d.toISOString().substr(0,7) );
// 2019-08
// 2019-08
</source>
</syntaxhighlight>


==PHP==
==PHP==
[[분류: PHP]]
[[분류: PHP]]
{{참고|PHP prev_month()}}
{{참고|PHP next_month()}}
<source lang='php'>
<syntaxhighlight lang='php'>
<?php
<?php
$mon = '2019-07';
$mon = '2019-07';
echo date("Y-m", strtotime("$mon +1 month"));
echo date("Y-m", strtotime("$mon +1 month"));
# 2019-08
# 2019-08
</source>
</syntaxhighlight>
 
==R==
[[분류: R]]
{{참고|R next_month()}}
<syntaxhighlight lang='r'>
require(lubridate)
mon <- "2019-07"
t <- as.Date(paste0(mon,'-01'))
month(t) <- month(t) + 1
next_mon <- format(t, "%Y-%m")
next_mon
## [1] "2019-08"
</syntaxhighlight>
<syntaxhighlight lang='r'>
require(lubridate)
next_mon <- function(mon) {
  t <- as.Date(paste0(mon,'-01'))
  month(t) <- month(t) + 1
  format(t, "%Y-%m")
}
next_mon("2019-07")
## [1] "2019-08"
next_mon("2019-12")
## [1] "2020-01"
</syntaxhighlight>


==같이 보기==
==같이 보기==
* [[함수 prev_month()]]
* [[함수 prev_month()]]
* [[함수 this_month()]]
* [[함수 this_month()]]

2020년 11월 2일 (월) 02:36 기준 최신판


1 개요[ | ]

함수 next_month()

2 JavaScript[ | ]

var d = new Date("2019-07");
d.setMonth(d.getMonth() + 1);
console.log( d.toISOString().substr(0,7) );
// 2019-08
var mon = "2019-07";
var d = new Date();
d.setFullYear(mon.substr(0,4));
d.setMonth(mon.substr(5,2));
console.log( d.toISOString().substr(0,7) );
// 2019-08

3 PHP[ | ]

<?php
$mon = '2019-07';
echo date("Y-m", strtotime("$mon +1 month"));
# 2019-08

4 R[ | ]

require(lubridate)
mon <- "2019-07"
t <- as.Date(paste0(mon,'-01'))
month(t) <- month(t) + 1
next_mon <- format(t, "%Y-%m")
next_mon
## [1] "2019-08"
require(lubridate)
next_mon <- function(mon) {
  t <- as.Date(paste0(mon,'-01'))
  month(t) <- month(t) + 1
  format(t, "%Y-%m")
}
next_mon("2019-07")
## [1] "2019-08"
next_mon("2019-12")
## [1] "2020-01"

5 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}