我正在使用 wordpress 为一家公司开发网站
从 2016 年 3 月 3 日开始,他们每个第 3 个星期四召开一次董事会 session
我正在尝试创建一个简码
我想回应下次 session 的时间。
这是我到目前为止得到的结果,但这是不正确的。
// ECHO next board_meeting - Use [next_board_meeting]
add_shortcode( 'next_board_meeting', 'next_board_meeting_shortcode' );
function next_board_meeting_shortcode( $str ) {
echo date_i18n('l j F', strtotime('next thursday +2 week'));
}
我一直在网上搜索类似的东西,但现在我在这里寻求您的帮助。
是否有一种简单的方法可以做到这一点,或者我是否需要创建一个复杂的 php 脚本?
请记住,我刚刚学会了如何在 php 中执行简单的任务。
最佳答案
此代码将使您获得当月的第三个星期四..
如果当前日期已经过了第 3 个星期四,那么它会显示下个月的第 3 个星期四。如果当前月份是 12 月并且已经过了第 3 个星期四,那么它会显示明年 1 月的第 3 个星期四
<?php
$current_date = strtotime(date("d.m.Y"));
//$final = date("Y-m-d", strtotime("+1 month", $time));
$FullMonth = date('F',$current_date);
$FullYear = date('Y',$current_date);
$Third_Thus = date('d F Y', strtotime('third thursday of '.$FullMonth.' '.$FullYear));
$ThirdThus_tmstamp = strtotime($Third_Thus);
if($current_date <= $ThirdThus_tmstamp){
echo date('d F Y', strtotime('third thursday of '.$FullMonth.' '.$FullYear));
}
else{
if($FullMonth != 'December'){
$FullMonth = date('F',strtotime("+1 month", $current_date));
$FullYear = date('Y',$current_date);
} else{
$Next_Year = strtotime("+1 year", $current_date);
$FullYear = date('Y',$Next_Year);
$FullMonth = date('F',strtotime("+1 month", $Next_Year));
}
echo date('d F Y', strtotime('third thursday of '.$FullMonth.' '.$FullYear));
}?>
This will show only one 3rd Thurs of either Current Month or Next Month depending on the current date.. If you want the 3rd Thurs of next 2-3 month then you can make some changes I guess now !!!
关于php - 从 2016 年 3 月 3 日开始每三个星期四回显,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35793878/