LoginSignup
0
0

グーグルカレンダーの今月・翌月分2個並べ表示を簡単なコードでほしい

Last updated at Posted at 2023-08-24

phpはstrtotimeが便利なので簡単に作りたい

これくらいのものはfunction.phpに書かずにさらっと済ませたいので。
パラメータ末尾にdates=~~で先頭日と末日を指定してやるだけでいけそう。

<?php
$_func_getgcal_date = function($str_ymd) {
    $tmp01d = date("Ym01",strtotime($str_ymd));
    return $tmp01d."/".date("Ymd",strtotime('last day of '.$tmp01d));
};
$ymd_now = date("Ym01",strtotime($date("Ymd")));
$ymd_next = date("Ym01",strtotime($ymd_now." +1 month"));
$ymd_prev = date("Ym01",strtotime($ymd_now." -1 month"));
?>
<div class="_col">
    <iframe src="https://calendar.google.com/calendar/embed?~~~~~~~&ctz=Asia/Tokyo&dates=<?php echo $_func_getgcal_date($ymd_now); ?>"></iframe>
</div>
<div class="_col">
    <iframe src="https://calendar.google.com/calendar/embed?~~~~~~~&ctz=Asia/Tokyo&dates=<?php echo $_func_getgcal_date($ymd_next); ?>"></iframe>
</div>
<div class="_col">
    <iframe src="https://calendar.google.com/calendar/embed?~~~~~~~&ctz=Asia/Tokyo&dates=<?php echo $_func_getgcal_date($ymd_prev); ?>"></iframe>
</div>

※注意
あくまで簡易的なものなので、ずれが発生する日付があります。
8月31日9月30日と大の月小の月が続くときの31日等々。

→1日をとって基準とすることで修正済み。
対策していくと関数が膨らみますので、ベースの簡易例としてお受け取りください。

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