함수 next_month()


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 }}