获取下周几日期的方法:
1、使用“strtotime("next 指定星期")”语句获取下周指定星期的时间戳;
2、使用“date("Y-m-d",时间戳)”语句将获取的时间戳转换为日期,并使用echo输出即可。
PHP获取下周几日期的方法:
新建一个php文件,命名为test.php,用于讲解php如何获取下个星期四的日期。
在test.php文件中,使用header()方法设置页面的编码格式为utf-8,避免页面输出中文时乱码。
在test.php文件中,以“next+星期”的格式,定义一个字符串。
在test.php文件中,使用strtotime()函数利用上一步的字符串获得下个星期四日期的时间戳。
在test.php文件中,再使用date()函数将时间戳转换为日期,并使用echo输出转换的结果。
在浏览器打开test.php文件,查看结果。
<?php
header("Content-type:text/html;charset=utf-8");
$nstr = "next Thursday";
$res = strtotime($nstr);
echo "下个星期四的日期为:" . date("Y-m-d", $res);
?>
总结:
1、以“next+星期”的格式,定义一个字符串。
2、使用strtotime()函数利用上一步的字符串获得下个星期四日期的时间戳。
3、再使用date()函数将时间戳转换为日期,并使用echo输出转换的结果。