有没有办法在特定日期的PHP中查找星期几.
我不是故意的
date('D', $timestamp);
Run Code Online (Sandbox Code Playgroud)
我的意思是,如果我要提供像2010-10-21这样的日期,它将返回"第三个星期四".
Tat*_*nen 12
不是直接的,你需要一个辅助函数:
function literalDate($timestamp) {
$timestamp = is_numeric($timestamp) ? $timestamp : strtotime($timestamp);
$weekday = date('l', $timestamp);
$month = date('M', $timestamp);
$ord = 0;
while(date('M', ($timestamp = strtotime('-1 week', $timestamp))) == $month) {
$ord++;
}
$lit = array('first', 'second', 'third', 'fourth', 'fifth');
return strtolower($lit[$ord].' '.$weekday);
}
echo literalDate('2010-10-21'); // outputs "third thursday"
Run Code Online (Sandbox Code Playgroud)
工作范例:
| 归档时间: |
|
| 查看次数: |
2311 次 |
| 最近记录: |